Package java.util.concurrent

Examples of java.util.concurrent.ThreadPoolExecutor


                onJobRejected(r);
            }
        };
        log.info("ThreadPoolExecutor configuration: corePoolSize = {}, maxPoolSize={}, keepAliveTimeSeconds={}",
                new Object[] { corePoolSize, maximumPoolSize, keepAliveTimeSeconds });
        executor = new ThreadPoolExecutor(corePoolSize, maximumPoolSize,
                keepAliveTimeSeconds, unit, workQueue, handler);
    }
View Full Code Here


                return t;
            }

        };
        m_writeThread = MoreExecutors.listeningDecorator(
                new ThreadPoolExecutor(
                        1,
                        1,
                        0,
                        TimeUnit.MILLISECONDS,
                        new LinkedBlockingQueue<Runnable>(),
                        tf));

        tf = new ThreadFactory() {

            @Override
            public Thread newThread(Runnable r) {
                Thread t = new Thread( r, "JitCask[" + m_caskPath + "] Sync Thread");
                t.setDaemon(true);
                return t;
            }

        };
        m_syncThread = MoreExecutors.listeningDecorator(
                new ScheduledThreadPoolExecutor(
                1,
                tf));

        tf = new ThreadFactory() {
            private final AtomicInteger m_counter = new AtomicInteger();

            @Override
            public Thread newThread(Runnable r) {
                Thread t = new Thread(
                        null,
                        r,
                        "JitCask[" + m_caskPath + "] Read Thread " + m_counter.incrementAndGet(),
                        1024 * 256);
                t.setDaemon(true);
                return t;
            }

        };
        m_readThreads = MoreExecutors.listeningDecorator(
                new ThreadPoolExecutor(
                        READ_QUEUE_DEPTH,
                        READ_QUEUE_DEPTH,
                        0,
                        TimeUnit.MILLISECONDS,
                        new LinkedBlockingQueue<Runnable>(),
                        tf,
                        new ThreadPoolExecutor.AbortPolicy()));

        tf = new ThreadFactory() {
            private final AtomicInteger m_counter = new AtomicInteger();

            @Override
            public Thread newThread(Runnable r) {
                Thread t = new Thread(
                        null,
                        r,
                        "JitCask[" + m_caskPath + "] Compression Thread " + m_counter.incrementAndGet(),
                        1024 * 256);
                t.setDaemon(true);
                return t;
            }

        };

        final int availableProcs = Runtime.getRuntime().availableProcessors() / 2;
        m_compressionThreads =
                MoreExecutors.listeningDecorator(
                        new ThreadPoolExecutor(
                                availableProcs,
                                availableProcs,
                                0,
                                TimeUnit.MILLISECONDS,
                                new LinkedBlockingQueue<Runnable>(availableProcs),
View Full Code Here

   * @param queueSize
   *            the size of the queue to store Runnables when all threads are busy
   * @return the new ExecutorService
   */
  public static ThreadPoolExecutor newFixedThreadPool(int threads, String groupname, int queueSize) {
    return new ThreadPoolExecutor( threads, threads, 0L, TimeUnit.MILLISECONDS, new LinkedBlockingQueue<Runnable>(
        queueSize ), new SearchThreadFactory( groupname ), new BlockPolicy() );
  }
View Full Code Here

//    Arrays.fill(grad, dim);
//    for(int x = 0 ; x < dim ; x++)
//      grad[x] *= kernel.getGammas()[x];
   
    //1 job par ligne
    ThreadPoolExecutor threadPool = ThreadPoolServer.getThreadPoolExecutor();
    Queue<Future<?>> futures = new LinkedList<Future<?>>();
   
    class GradRunnable implements Runnable {
      GeneralizedDoubleGaussL2 kernel;
      int i;
      public GradRunnable(GeneralizedDoubleGaussL2 kernel, int i) {
        this.kernel = kernel;
        this.i = i;
      }
     
      public void run() {
        double[][] matrix = kernel.distanceMatrixUnthreaded(listOfExamples, i);
        double sum = 0;
        for(int x = 0 ; x < matrix.length ; x++)
          if(lambda_matrix[x] != null)
            for(int y = 0 ; y < matrix.length ; y++)
              sum += matrix[x][y]*lambda_matrix[x][y];
//        grad[i] = 0.5*sum/(matrix.length*matrix.length);
        grad[i] += 0.5*sum;
      }
    }
   
    for(int i = 0 ; i < grad.length ; i++) {
      Runnable r = new GradRunnable(kernel, i);
      futures.add(threadPool.submit(r));
    }
   
    //wait for all jobs
    while(!futures.isEmpty())
    {
View Full Code Here

   * Tells the system wide ThreadPoolServer (Singleton pattern)
   *
   * @return system wide instance of this class.
   */
  public static ThreadPoolExecutor getThreadPoolExecutor() {
    ThreadPoolExecutor executor;
    int nbcpu = Runtime.getRuntime().availableProcessors();
    executor = new ThreadPoolExecutor(nbcpu, 2 * nbcpu, 1,
        TimeUnit.SECONDS, new LinkedBlockingQueue<Runnable>());
    executor.prestartAllCoreThreads();
    executor.allowCoreThreadTimeOut(true);
    return executor;
  }
View Full Code Here

   * @return the resulting matrix
   */
  public double[][] getMatrix(final double[][] matrix)
  {
    //one job per line of the matrix
    ThreadPoolExecutor threadPool = ThreadPoolServer.getThreadPoolExecutor();
    Queue<Future<?>> futures = new LinkedList<Future<?>>();
   
    int increm = matrix.length / nbjobs  + 1 ;
   
    try
    {
      for(int i = 0 ; i < matrix.length ; i += increm)
      {
        final int from = i;
        final int to = Math.min(matrix.length, i+increm);
       
       
        Runnable r = new Runnable(){
          public void run() {
            doLines(matrix, from, to);
          }
        };
       
        futures.add(threadPool.submit(r));
      }

      //wait for all jobs
      while(!futures.isEmpty())
      {
View Full Code Here

  public double[] getVector(final double[] vector)
  {
    try
    {
      //one job per line of the matrix
      ThreadPoolExecutor threadPool = ThreadPoolServer.getThreadPoolExecutor();
      Queue<Future<?>> futures = new LinkedList<Future<?>>();
     
      int nbcpu = Runtime.getRuntime().availableProcessors();
      int increm = vector.length / nbcpu + 1;
     
      for(int i = 0 ; i < vector.length ; i += increm)
      {
        final int min = i;
        final int max = Math.min(vector.length, i+increm);
        Runnable r = new Runnable(){
          @Override
          public void run() {
            doBlock(min, max, vector);
          }
        };
       
        futures.add(threadPool.submit(r));
      }

      //wait for all jobs
      while(!futures.isEmpty())
        futures.remove().get();
View Full Code Here

    if(A.length < granularity)
      return MatrixOperations.trans(A);
   
    final double[][] out = new double[A[0].length][A.length];
   
    ThreadPoolExecutor exec = ThreadPoolServer.getThreadPoolExecutor();
    List<Future<Object>> futures = new ArrayList<Future<Object>>();
   
    for(int jj = 0 ; jj < A.length ; jj++) {
      final int j = jj;
      futures.add(exec.submit(new Callable<Object>() {

        @Override
        public Object call() {
          for(int i = 0 ; i < A[0].length ; i++) {
              out[i][j] = A[j][i];
View Full Code Here

      return MatrixOperations.transi(A);
   
    if(!MatrixOperations.isSquare(A))
      throw new ArithmeticException("Matrix must be square.");

    ThreadPoolExecutor exec = ThreadPoolServer.getThreadPoolExecutor();
    List<Future<Object>> futures = new ArrayList<Future<Object>>();
    final double[][] m = A;
   
    for(int ii = 0 ; ii < A.length ; ii++) {
      final int i = ii;
      futures.add(exec.submit(new Callable<Object>() {
        double tmp;
        @Override
        public Object call() {
          for(int j = i+1 ; j < m[0].length; j++) {
            tmp = m[i][j];
View Full Code Here

      throw new ArithmeticException("Matrix dimensions must agree.");
    }
   
    final double[][] out = new double[m][n];
   
    ThreadPoolExecutor exec = ThreadPoolServer.getThreadPoolExecutor();
    List<Future<Object>> futures = new ArrayList<Future<Object>>();
   
    for(int ii = 0 ; ii < m ; ii++) {
      final int i = ii;
      futures.add(exec.submit(new Callable<Object>() {

        @Override
        public Object call() throws Exception {
          for(int j = 0 ; j < n ; j++) {
            double sum = 0;
View Full Code Here

TOP

Related Classes of java.util.concurrent.ThreadPoolExecutor

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.