Search in sources :

Example 51 with ThreadPoolExecutor

use of java.util.concurrent.ThreadPoolExecutor in project hbase by apache.

the class TestPartitionedMobCompactor method createThreadPool.

private static ExecutorService createThreadPool() {
    int maxThreads = 10;
    long keepAliveTime = 60;
    final SynchronousQueue<Runnable> queue = new SynchronousQueue<>();
    ThreadPoolExecutor pool = new ThreadPoolExecutor(1, maxThreads, keepAliveTime, TimeUnit.SECONDS, queue, Threads.newDaemonThreadFactory("MobFileCompactionChore"), new RejectedExecutionHandler() {

        @Override
        public void rejectedExecution(Runnable r, ThreadPoolExecutor executor) {
            try {
                // waiting for a thread to pick up instead of throwing exceptions.
                queue.put(r);
            } catch (InterruptedException e) {
                throw new RejectedExecutionException(e);
            }
        }
    });
    ((ThreadPoolExecutor) pool).allowCoreThreadTimeOut(true);
    return pool;
}
Also used : RejectedExecutionHandler(java.util.concurrent.RejectedExecutionHandler) SynchronousQueue(java.util.concurrent.SynchronousQueue) ThreadPoolExecutor(java.util.concurrent.ThreadPoolExecutor) RejectedExecutionException(java.util.concurrent.RejectedExecutionException)

Example 52 with ThreadPoolExecutor

use of java.util.concurrent.ThreadPoolExecutor in project hbase by apache.

the class TestProcedureMember method testNoTaskToBeRunFromRequest.

/**
   * Test that the cohort member correctly doesn't attempt to start a task when the builder cannot
   * correctly build a new task for the requested operation
   * @throws Exception on failure
   */
@Test
public void testNoTaskToBeRunFromRequest() throws Exception {
    ThreadPoolExecutor pool = mock(ThreadPoolExecutor.class);
    when(mockBuilder.buildSubprocedure(op, data)).thenReturn(null).thenThrow(new IllegalStateException("Wrong state!"), new IllegalArgumentException("can't understand the args"));
    member = new ProcedureMember(mockMemberComms, pool, mockBuilder);
    // builder returns null
    // build a new operation
    Subprocedure subproc = member.createSubprocedure(op, data);
    member.submitSubprocedure(subproc);
    // throws an illegal state exception
    try {
        // build a new operation
        Subprocedure subproc2 = member.createSubprocedure(op, data);
        member.submitSubprocedure(subproc2);
    } catch (IllegalStateException ise) {
    }
    // throws an illegal argument exception
    try {
        // build a new operation
        Subprocedure subproc3 = member.createSubprocedure(op, data);
        member.submitSubprocedure(subproc3);
    } catch (IllegalArgumentException iae) {
    }
    // no request should reach the pool
    verifyZeroInteractions(pool);
// get two abort requests
// TODO Need to do another refactor to get this to propagate to the coordinator.
// verify(mockMemberComms, times(2)).sendMemberAborted(any(Subprocedure.class), any(ExternalException.class));
}
Also used : ThreadPoolExecutor(java.util.concurrent.ThreadPoolExecutor) Test(org.junit.Test)

Example 53 with ThreadPoolExecutor

use of java.util.concurrent.ThreadPoolExecutor in project hbase by apache.

the class ThriftServer method getTThreadPoolServer.

private static TServer getTThreadPoolServer(TProtocolFactory protocolFactory, TProcessor processor, TTransportFactory transportFactory, int workerThreads, InetSocketAddress inetSocketAddress, int backlog, int clientTimeout, ThriftMetrics metrics) throws TTransportException {
    TServerTransport serverTransport = new TServerSocket(new TServerSocket.ServerSocketTransportArgs().bindAddr(inetSocketAddress).backlog(backlog).clientTimeout(clientTimeout));
    log.info("starting HBase ThreadPool Thrift server on " + inetSocketAddress.toString());
    TThreadPoolServer.Args serverArgs = new TThreadPoolServer.Args(serverTransport);
    serverArgs.processor(processor);
    serverArgs.transportFactory(transportFactory);
    serverArgs.protocolFactory(protocolFactory);
    if (workerThreads > 0) {
        serverArgs.maxWorkerThreads(workerThreads);
    }
    ThreadPoolExecutor executor = new THBaseThreadPoolExecutor(serverArgs.minWorkerThreads, serverArgs.maxWorkerThreads, serverArgs.stopTimeoutVal, TimeUnit.SECONDS, new SynchronousQueue<>(), metrics);
    serverArgs.executorService(executor);
    return new TThreadPoolServer(serverArgs);
}
Also used : TServerSocket(org.apache.thrift.transport.TServerSocket) THBaseThreadPoolExecutor(org.apache.hadoop.hbase.thrift.THBaseThreadPoolExecutor) ThreadPoolExecutor(java.util.concurrent.ThreadPoolExecutor) TThreadPoolServer(org.apache.thrift.server.TThreadPoolServer) TServerTransport(org.apache.thrift.transport.TServerTransport) THBaseThreadPoolExecutor(org.apache.hadoop.hbase.thrift.THBaseThreadPoolExecutor)

Example 54 with ThreadPoolExecutor

use of java.util.concurrent.ThreadPoolExecutor in project hbase by apache.

the class ThriftServer method createExecutor.

private static ExecutorService createExecutor(int workerThreads, int maxCallQueueSize, ThriftMetrics metrics) {
    CallQueue callQueue;
    if (maxCallQueueSize > 0) {
        callQueue = new CallQueue(new LinkedBlockingQueue<>(maxCallQueueSize), metrics);
    } else {
        callQueue = new CallQueue(new LinkedBlockingQueue<>(), metrics);
    }
    ThreadFactoryBuilder tfb = new ThreadFactoryBuilder();
    tfb.setDaemon(true);
    tfb.setNameFormat("thrift2-worker-%d");
    ThreadPoolExecutor pool = new THBaseThreadPoolExecutor(workerThreads, workerThreads, Long.MAX_VALUE, TimeUnit.SECONDS, callQueue, tfb.build(), metrics);
    pool.prestartAllCoreThreads();
    return pool;
}
Also used : CallQueue(org.apache.hadoop.hbase.thrift.CallQueue) ThreadFactoryBuilder(com.google.common.util.concurrent.ThreadFactoryBuilder) THBaseThreadPoolExecutor(org.apache.hadoop.hbase.thrift.THBaseThreadPoolExecutor) ThreadPoolExecutor(java.util.concurrent.ThreadPoolExecutor) LinkedBlockingQueue(java.util.concurrent.LinkedBlockingQueue) THBaseThreadPoolExecutor(org.apache.hadoop.hbase.thrift.THBaseThreadPoolExecutor)

Example 55 with ThreadPoolExecutor

use of java.util.concurrent.ThreadPoolExecutor in project hbase by apache.

the class TestRegionOpen method testPriorityRegionIsOpenedWithSeparateThreadPool.

@Test(timeout = 60000)
public void testPriorityRegionIsOpenedWithSeparateThreadPool() throws Exception {
    ThreadPoolExecutor exec = getRS().getExecutorService().getExecutorThreadPool(ExecutorType.RS_OPEN_PRIORITY_REGION);
    assertEquals(0, exec.getCompletedTaskCount());
    HTableDescriptor htd = new HTableDescriptor(tableName);
    htd.setPriority(HConstants.HIGH_QOS);
    htd.addFamily(new HColumnDescriptor(HConstants.CATALOG_FAMILY));
    try (Connection connection = ConnectionFactory.createConnection(HTU.getConfiguration());
        Admin admin = connection.getAdmin()) {
        admin.createTable(htd);
    }
    assertEquals(1, exec.getCompletedTaskCount());
}
Also used : HColumnDescriptor(org.apache.hadoop.hbase.HColumnDescriptor) Connection(org.apache.hadoop.hbase.client.Connection) ThreadPoolExecutor(java.util.concurrent.ThreadPoolExecutor) Admin(org.apache.hadoop.hbase.client.Admin) HTableDescriptor(org.apache.hadoop.hbase.HTableDescriptor) Test(org.junit.Test)

Aggregations

ThreadPoolExecutor (java.util.concurrent.ThreadPoolExecutor)397 Test (org.junit.Test)79 ExecutorService (java.util.concurrent.ExecutorService)74 LinkedBlockingQueue (java.util.concurrent.LinkedBlockingQueue)60 ThreadFactory (java.util.concurrent.ThreadFactory)38 ArrayList (java.util.ArrayList)34 IOException (java.io.IOException)33 ScheduledThreadPoolExecutor (java.util.concurrent.ScheduledThreadPoolExecutor)30 SynchronousQueue (java.util.concurrent.SynchronousQueue)29 ArrayBlockingQueue (java.util.concurrent.ArrayBlockingQueue)23 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)23 RejectedExecutionHandler (java.util.concurrent.RejectedExecutionHandler)22 ExecutionException (java.util.concurrent.ExecutionException)21 Future (java.util.concurrent.Future)20 ThreadFactoryBuilder (com.google.common.util.concurrent.ThreadFactoryBuilder)18 CountDownLatch (java.util.concurrent.CountDownLatch)18 Test (org.testng.annotations.Test)18 RejectedExecutionException (java.util.concurrent.RejectedExecutionException)16 SizedScheduledExecutorService (org.apache.camel.util.concurrent.SizedScheduledExecutorService)16 HashMap (java.util.HashMap)14