Search in sources :

Example 86 with SynchronousQueue

use of java.util.concurrent.SynchronousQueue in project hive by apache.

the class TestJdbcWithMiniHS2 method startConcurrencyTest.

private static void startConcurrencyTest(Connection conn, String tableName, int numTasks) {
    // Start concurrent testing
    int poolSize = 100;
    SynchronousQueue<Runnable> executorQueue = new SynchronousQueue<Runnable>();
    ExecutorService workers = new ThreadPoolExecutor(1, poolSize, 20, TimeUnit.SECONDS, executorQueue);
    List<Future<Boolean>> list = startTasks(workers, conn, tableName, numTasks);
    finishTasks(list, workers);
}
Also used : SynchronousQueue(java.util.concurrent.SynchronousQueue) ExecutorService(java.util.concurrent.ExecutorService) Future(java.util.concurrent.Future) ThreadPoolExecutor(java.util.concurrent.ThreadPoolExecutor)

Example 87 with SynchronousQueue

use of java.util.concurrent.SynchronousQueue in project hive by apache.

the class TestJdbcWithMiniHS2 method testParallelCompilation4.

@Test
public void testParallelCompilation4() throws Exception {
    Statement stmt = conTestDb.createStatement();
    stmt.execute("set hive.driver.parallel.compilation=true");
    stmt.execute("set hive.server2.async.exec.async.compile=false");
    stmt.close();
    Connection conn = getConnection(testDbName);
    stmt = conn.createStatement();
    stmt.execute("set hive.driver.parallel.compilation=true");
    stmt.execute("set hive.server2.async.exec.async.compile=false");
    stmt.close();
    int poolSize = 100;
    SynchronousQueue<Runnable> executorQueue1 = new SynchronousQueue<Runnable>();
    ExecutorService workers1 = new ThreadPoolExecutor(1, poolSize, 20, TimeUnit.SECONDS, executorQueue1);
    SynchronousQueue<Runnable> executorQueue2 = new SynchronousQueue<Runnable>();
    ExecutorService workers2 = new ThreadPoolExecutor(1, poolSize, 20, TimeUnit.SECONDS, executorQueue2);
    List<Future<Boolean>> list1 = startTasks(workers1, conTestDb, tableName, 10);
    List<Future<Boolean>> list2 = startTasks(workers2, conn, tableName, 10);
    finishTasks(list1, workers1);
    finishTasks(list2, workers2);
    conn.close();
}
Also used : Statement(java.sql.Statement) SynchronousQueue(java.util.concurrent.SynchronousQueue) Connection(java.sql.Connection) ExecutorService(java.util.concurrent.ExecutorService) Future(java.util.concurrent.Future) ThreadPoolExecutor(java.util.concurrent.ThreadPoolExecutor) Test(org.junit.Test)

Example 88 with SynchronousQueue

use of java.util.concurrent.SynchronousQueue in project zookeeper by apache.

the class QuorumCnxManager method initializeConnectionExecutor.

// we always use the Connection Executor during connection initiation (to handle connection
// timeouts), and optionally use it during receiving connections (as the Quorum SASL authentication
// can take extra time)
private void initializeConnectionExecutor(final long mySid, final int quorumCnxnThreadsSize) {
    final AtomicInteger threadIndex = new AtomicInteger(1);
    SecurityManager s = System.getSecurityManager();
    final ThreadGroup group = (s != null) ? s.getThreadGroup() : Thread.currentThread().getThreadGroup();
    final ThreadFactory daemonThFactory = runnable -> new Thread(group, runnable, String.format("QuorumConnectionThread-[myid=%d]-%d", mySid, threadIndex.getAndIncrement()));
    this.connectionExecutor = new ThreadPoolExecutor(3, quorumCnxnThreadsSize, 60, TimeUnit.SECONDS, new SynchronousQueue<>(), daemonThFactory);
    this.connectionExecutor.allowCoreThreadTimeOut(true);
}
Also used : Arrays(java.util.Arrays) ServiceUtils(org.apache.zookeeper.util.ServiceUtils) BufferedInputStream(java.io.BufferedInputStream) NetUtils(org.apache.zookeeper.common.NetUtils) Enumeration(java.util.Enumeration) SSLSocket(javax.net.ssl.SSLSocket) LoggerFactory(org.slf4j.LoggerFactory) ByteBuffer(java.nio.ByteBuffer) InetAddress(java.net.InetAddress) ServerSocket(java.net.ServerSocket) DataOutputStream(java.io.DataOutputStream) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Duration(java.time.Duration) Map(java.util.Map) ThreadFactory(java.util.concurrent.ThreadFactory) ConfigUtils(org.apache.zookeeper.server.util.ConfigUtils) NetUtils.formatInetAddr(org.apache.zookeeper.common.NetUtils.formatInetAddr) SynchronousQueue(java.util.concurrent.SynchronousQueue) ConfigException(org.apache.zookeeper.server.quorum.QuorumPeerConfig.ConfigException) Collection(java.util.Collection) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) ZooKeeperThread(org.apache.zookeeper.server.ZooKeeperThread) Set(java.util.Set) BlockingQueue(java.util.concurrent.BlockingQueue) InetSocketAddress(java.net.InetSocketAddress) Collectors(java.util.stream.Collectors) Executors(java.util.concurrent.Executors) CountDownLatch(java.util.concurrent.CountDownLatch) List(java.util.List) X509Exception(org.apache.zookeeper.common.X509Exception) UnresolvedAddressException(java.nio.channels.UnresolvedAddressException) DataInputStream(java.io.DataInputStream) Socket(java.net.Socket) ThreadPoolExecutor(java.util.concurrent.ThreadPoolExecutor) CircularBlockingQueue(org.apache.zookeeper.util.CircularBlockingQueue) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) QuorumVerifier(org.apache.zookeeper.server.quorum.flexible.QuorumVerifier) Supplier(java.util.function.Supplier) BufferedOutputStream(java.io.BufferedOutputStream) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) SocketException(java.net.SocketException) SocketTimeoutException(java.net.SocketTimeoutException) ExecutorService(java.util.concurrent.ExecutorService) Logger(org.slf4j.Logger) UTF_8(java.nio.charset.StandardCharsets.UTF_8) QuorumAuthServer(org.apache.zookeeper.server.quorum.auth.QuorumAuthServer) IOException(java.io.IOException) ExitCode(org.apache.zookeeper.server.ExitCode) UnknownHostException(java.net.UnknownHostException) BufferUnderflowException(java.nio.BufferUnderflowException) TimeUnit(java.util.concurrent.TimeUnit) AtomicLong(java.util.concurrent.atomic.AtomicLong) QuorumAuthLearner(org.apache.zookeeper.server.quorum.auth.QuorumAuthLearner) Closeable(java.io.Closeable) Collections(java.util.Collections) ThreadFactory(java.util.concurrent.ThreadFactory) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) SynchronousQueue(java.util.concurrent.SynchronousQueue) ThreadPoolExecutor(java.util.concurrent.ThreadPoolExecutor) ZooKeeperThread(org.apache.zookeeper.server.ZooKeeperThread)

Example 89 with SynchronousQueue

use of java.util.concurrent.SynchronousQueue in project dubbo by alibaba.

the class FixedThreadPool method getExecutor.

@Override
public Executor getExecutor(URL url) {
    String name = url.getParameter(THREAD_NAME_KEY, DEFAULT_THREAD_NAME);
    int threads = url.getParameter(THREADS_KEY, DEFAULT_THREADS);
    int queues = url.getParameter(QUEUES_KEY, DEFAULT_QUEUES);
    return new ThreadPoolExecutor(threads, threads, 0, TimeUnit.MILLISECONDS, queues == 0 ? new SynchronousQueue<Runnable>() : (queues < 0 ? new LinkedBlockingQueue<Runnable>() : new LinkedBlockingQueue<Runnable>(queues)), new NamedInternalThreadFactory(name, true), new AbortPolicyWithReport(name, url));
}
Also used : NamedInternalThreadFactory(org.apache.dubbo.common.threadlocal.NamedInternalThreadFactory) SynchronousQueue(java.util.concurrent.SynchronousQueue) AbortPolicyWithReport(org.apache.dubbo.common.threadpool.support.AbortPolicyWithReport) ThreadPoolExecutor(java.util.concurrent.ThreadPoolExecutor) LinkedBlockingQueue(java.util.concurrent.LinkedBlockingQueue)

Example 90 with SynchronousQueue

use of java.util.concurrent.SynchronousQueue in project jmeter by apache.

the class ResourcesDownloader method init.

private void init() {
    LOG.info("Creating ResourcesDownloader with keepalive_inseconds : {}", THREAD_KEEP_ALIVE_TIME);
    concurrentExecutor = new ThreadPoolExecutor(MIN_POOL_SIZE, MAX_POOL_SIZE, THREAD_KEEP_ALIVE_TIME, TimeUnit.SECONDS, new SynchronousQueue<>(), r -> {
        Thread t = new Thread(r);
        // $NON-NLS-1$
        t.setName("ResDownload-" + t.getName());
        t.setDaemon(true);
        return t;
    }) {
    };
}
Also used : JMeterUtils(org.apache.jmeter.util.JMeterUtils) Logger(org.slf4j.Logger) SynchronousQueue(java.util.concurrent.SynchronousQueue) ThreadPoolExecutor(java.util.concurrent.ThreadPoolExecutor) LoggerFactory(org.slf4j.LoggerFactory) CollectionProperty(org.apache.jmeter.testelement.property.CollectionProperty) Callable(java.util.concurrent.Callable) CompletionService(java.util.concurrent.CompletionService) ArrayList(java.util.ArrayList) ExecutionException(java.util.concurrent.ExecutionException) TimeUnit(java.util.concurrent.TimeUnit) List(java.util.List) Future(java.util.concurrent.Future) ExecutorCompletionService(java.util.concurrent.ExecutorCompletionService) SynchronousQueue(java.util.concurrent.SynchronousQueue) ThreadPoolExecutor(java.util.concurrent.ThreadPoolExecutor)

Aggregations

SynchronousQueue (java.util.concurrent.SynchronousQueue)120 ThreadPoolExecutor (java.util.concurrent.ThreadPoolExecutor)64 ExecutorService (java.util.concurrent.ExecutorService)21 ThreadFactory (java.util.concurrent.ThreadFactory)15 LinkedBlockingQueue (java.util.concurrent.LinkedBlockingQueue)13 ArrayList (java.util.ArrayList)12 RejectedExecutionHandler (java.util.concurrent.RejectedExecutionHandler)10 IOException (java.io.IOException)9 Test (org.junit.Test)9 ScheduledThreadPoolExecutor (java.util.concurrent.ScheduledThreadPoolExecutor)8 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)8 InputStream (java.io.InputStream)7 OutputStream (java.io.OutputStream)7 BlockingQueue (java.util.concurrent.BlockingQueue)7 XMPPException (org.jivesoftware.smack.XMPPException)7 Future (java.util.concurrent.Future)6 RejectedExecutionException (java.util.concurrent.RejectedExecutionException)6 CountDownLatch (java.util.concurrent.CountDownLatch)5 XMPPConnection (org.jivesoftware.smack.XMPPConnection)5 List (java.util.List)4