Package java.util.concurrent

Examples of java.util.concurrent.ThreadPoolExecutor


  protected void startExecutorPool() {
    if (m_executorPool != null) {
      m_executorPool.shutdownNow();
    }

    m_executorPool = new ThreadPoolExecutor(m_numExecutionSlots, m_numExecutionSlots,
        120, TimeUnit.SECONDS, new LinkedBlockingQueue<Runnable>());
  }
View Full Code Here


   
    if (m_executorPool != null) {
      m_executorPool.shutdownNow();
    }
   
    m_executorPool = new ThreadPoolExecutor(m_executionSlots, m_executionSlots,
        120, TimeUnit.SECONDS, new LinkedBlockingQueue<Runnable>());
  }
View Full Code Here

  protected void startExecutorPool() {
    if (m_executorPool != null) {
      m_executorPool.shutdownNow();
    }

    m_executorPool = new ThreadPoolExecutor(m_numExecutionSlots, m_numExecutionSlots,
        120, TimeUnit.SECONDS, new LinkedBlockingQueue<Runnable>());
  }
View Full Code Here

        // 1. Create a Selector
        selector=Selector.open();

        // Create a thread pool (Executor)
        executor=new ThreadPoolExecutor(MIN_THREAD_POOL_SIZE, MAX_THREAD_POOL_SIZE, 30000, TimeUnit.MILLISECONDS,
                                        new LinkedBlockingQueue(1000));

        for (Iterator it=mappings.keySet().iterator(); it.hasNext();) {
            key=(MyInetSocketAddress) it.next();
            value=(MyInetSocketAddress) mappings.get(key);
View Full Code Here

 
  public ThreadReuseExecutor(String name, int maximumPoolSize) {
    this.maximumPoolSize = maximumPoolSize;
    this.poolName = name;
   
    tpe = new ThreadPoolExecutor(0,
        maximumPoolSize, 2, TimeUnit.MINUTES,
        new SynchronousQueue<Runnable>(), new NamedThreadFactory("Worker")) { //$NON-NLS-1$
      @Override
      protected void afterExecute(Runnable r, Throwable t) {
        if (t != null) {
View Full Code Here

        this.component = component;
        this.manager = manager;

        // Create a pool of threads that will process requests received by this component. If more
        // threads are required then the command will be executed on the SocketReadThread process
        threadPool = new ThreadPoolExecutor(maxThreads, maxThreads, 15, TimeUnit.SECONDS,
                        new LinkedBlockingQueue<Runnable>(), new ThreadPoolExecutor.CallerRunsPolicy());
    }
View Full Code Here

   * of a {@link RemoteBitStreamIndex}, even if the latter would be usable.
   */

  public static void start( final Index index, final ServerSocket serverSocket, boolean forceRemoteIndex ) throws IOException {
    LOGGER.info( "Index server started at " + serverSocket.getLocalSocketAddress() );
    ThreadPoolExecutor threadPool = (ThreadPoolExecutor)Executors.newCachedThreadPool();
    Socket socket;
    final SocketAddress localSocketAddress = serverSocket.getLocalSocketAddress();
    int command;
    for ( ;; ) {
     
      socket = serverSocket.accept();
      command = socket.getInputStream().read();
      LOGGER.debug( "Remote command: " + command );
     
      switch( command ) {
      case GET_INDEX:
        DataInputStream dis = new DataInputStream( socket.getInputStream() );
        DataOutputStream dos = new DataOutputStream( socket.getOutputStream() );
        boolean randomAccess = dis.readBoolean();
        boolean documentSizes = dis.readBoolean();
       
        if ( index instanceof BitStreamIndex && ! forceRemoteIndex ) {
          BitStreamIndex localIndex = (BitStreamIndex)index;
          if ( randomAccess && localIndex.offsets == null ) {
            randomAccess = false;
            LOGGER.warn( "Random access will not be available for index " + localIndex );
          }
          /** Note that in case of Golomb or interpolative position coding
           *  we are forced to serialise and transfer the entire size list,
           *  or decoding would be too slow. */
          BinIO.storeObject( new RemoteBitStreamIndex( localSocketAddress,
              index.numberOfDocuments, index.numberOfTerms,
              index.numberOfPostings, index.numberOfOccurrences,
              index.maxCount, localIndex.payload, localIndex.frequencyCoding, localIndex.pointerCoding,
              localIndex.countCoding,
              localIndex.positionCoding,
              localIndex.quantum,
              localIndex.height,
              localIndex.bufferSize,
              localIndex.termProcessor,
              localIndex.field,
              localIndex.properties,
              localIndex.termMap != null ? new RemoteTermMap( localSocketAddress, index.numberOfTerms ) : null,
              localIndex.prefixMap != null ? new RemotePrefixMap( localSocketAddress, index.numberOfTerms ) : null,
              localIndex.positionCoding == Coding.GOLOMB || localIndex.positionCoding == Coding.INTERPOLATIVE ? localIndex.sizes :
                ( documentSizes ? new RemoteSizeList( localSocketAddress, localIndex.numberOfDocuments ) : null ),
              randomAccess ? new RemoteOffsetList( localSocketAddress, localIndex.offsets.size() ) : null
          ), dos );
        }
        else
          BinIO.storeObject( new RemoteIndex( localSocketAddress, index.numberOfDocuments, index.numberOfTerms, index.numberOfPostings, index.numberOfOccurrences, index.maxCount, index.payload, index.hasCounts,
              index.hasPositions, index.termProcessor, index.field, ( documentSizes ? new RemoteSizeList( localSocketAddress, index.numberOfDocuments ) : null ), index.properties ), dos );
        dos.flush();
        break;
     
      case GET_INDEX_READER:
        threadPool.execute( new RemoteIndexReader.ServerThread( socket, index ) );
        break;

     
      case GET_TERM_MAP:
        threadPool.execute( new RemoteTermMap.ServerThread( socket, ((BitStreamIndex)index).termMap ) );
        break;

      case GET_PREFIX_MAP:
        threadPool.execute( new RemotePrefixMap.ServerThread( socket, ((BitStreamIndex)index).prefixMap ) );
        break;

      case GET_SIZE_LIST:
        threadPool.execute( new RemoteSizeList.ServerThread( socket, index.sizes ) );
        break;
       
      case GET_OFFSET_LIST:
        threadPool.execute( new RemoteOffsetList.ServerThread( socket, ((BitStreamIndex)index).offsets ) );
        break;
       
      case GET_CLIENT_INPUT_STREAM:
        threadPool.execute( new RemoteInputStream.ServerThread( socket, ((BitStreamIndex)index).getInputStream() ) );
        break;
      }

    }
  }
View Full Code Here

  private static int defaultKeepAliveTime = 120;
  private static TimeUnit defaultTimeUnit = TimeUnit.SECONDS;

  public static void initPool(String poolName, int corePoolSize,
      int maximumPoolSize, int keepAliveTime, TimeUnit timeUnit) {
    ThreadPoolExecutor threadPoolExecutor = (ThreadPoolExecutor) poolMap.get(poolName);
    if(threadPoolExecutor!=null) {
      logger.log(Level.FINE, "{0} will be shutdown and re-created", poolName);
      threadPoolExecutor.shutdown();
    }
    threadPoolExecutor = new ThreadPoolExecutor(corePoolSize,
        maximumPoolSize, keepAliveTime, timeUnit,
        new LinkedBlockingQueue<Runnable>());
    NamedThreadFactory threadFactory = new NamedThreadFactory("Thread_Pool_"+poolName);
    threadPoolExecutor.setThreadFactory(threadFactory);
    poolMap.put(poolName, threadPoolExecutor);
  }
View Full Code Here

    threadPoolExecutor.setThreadFactory(threadFactory);
    poolMap.put(poolName, threadPoolExecutor);
  }
 
  public static void addTask(String poolName, Runnable task) {
    ThreadPoolExecutor threadPoolExecutor = (ThreadPoolExecutor) poolMap.get(poolName);
    if(threadPoolExecutor==null) {
      threadPoolExecutor = new ThreadPoolExecutor(defaultCorePoolSize,
        defaultMaximumPoolSize, defaultKeepAliveTime, defaultTimeUnit,
        new LinkedBlockingQueue<Runnable>());
      NamedThreadFactory threadFactory = new NamedThreadFactory("Thread_Pool_"+poolName);
      threadPoolExecutor.setThreadFactory(threadFactory);
      poolMap.put(poolName, threadPoolExecutor);
    }
    threadPoolExecutor.execute(task);
  }
View Full Code Here

public final class ExecutorFactory {

    private ExecutorFactory() {}

    public static ThreadPoolExecutor newCachedThreadPool(String threadName) {
        return new ThreadPoolExecutor(0, Integer.MAX_VALUE, 60L, TimeUnit.SECONDS, new SynchronousQueue<Runnable>(), new NamedThreadFactory(threadName));
    }
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.