Search in sources :

Example 11 with SynchronousQueue

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

the class FixedThreadPool method getExecutor.

public Executor getExecutor(URL url) {
    String name = url.getParameter(Constants.THREAD_NAME_KEY, Constants.DEFAULT_THREAD_NAME);
    int threads = url.getParameter(Constants.THREADS_KEY, Constants.DEFAULT_THREADS);
    int queues = url.getParameter(Constants.QUEUES_KEY, Constants.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 NamedThreadFactory(name, true), new AbortPolicyWithReport(name, url));
}
Also used : NamedThreadFactory(com.alibaba.dubbo.common.utils.NamedThreadFactory) SynchronousQueue(java.util.concurrent.SynchronousQueue) AbortPolicyWithReport(com.alibaba.dubbo.common.threadpool.support.AbortPolicyWithReport) ThreadPoolExecutor(java.util.concurrent.ThreadPoolExecutor) LinkedBlockingQueue(java.util.concurrent.LinkedBlockingQueue)

Example 12 with SynchronousQueue

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

the class LimitedThreadPool method getExecutor.

public Executor getExecutor(URL url) {
    String name = url.getParameter(Constants.THREAD_NAME_KEY, Constants.DEFAULT_THREAD_NAME);
    int cores = url.getParameter(Constants.CORE_THREADS_KEY, Constants.DEFAULT_CORE_THREADS);
    int threads = url.getParameter(Constants.THREADS_KEY, Constants.DEFAULT_THREADS);
    int queues = url.getParameter(Constants.QUEUES_KEY, Constants.DEFAULT_QUEUES);
    return new ThreadPoolExecutor(cores, threads, Long.MAX_VALUE, TimeUnit.MILLISECONDS, queues == 0 ? new SynchronousQueue<Runnable>() : (queues < 0 ? new LinkedBlockingQueue<Runnable>() : new LinkedBlockingQueue<Runnable>(queues)), new NamedThreadFactory(name, true), new AbortPolicyWithReport(name, url));
}
Also used : NamedThreadFactory(com.alibaba.dubbo.common.utils.NamedThreadFactory) SynchronousQueue(java.util.concurrent.SynchronousQueue) AbortPolicyWithReport(com.alibaba.dubbo.common.threadpool.support.AbortPolicyWithReport) ThreadPoolExecutor(java.util.concurrent.ThreadPoolExecutor) LinkedBlockingQueue(java.util.concurrent.LinkedBlockingQueue)

Example 13 with SynchronousQueue

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

the class QuorumCnxManager method initializeAuth.

private void initializeAuth(final long mySid, final QuorumAuthServer authServer, final QuorumAuthLearner authLearner, final int quorumCnxnThreadsSize, final boolean quorumSaslAuthEnabled) {
    this.authServer = authServer;
    this.authLearner = authLearner;
    this.quorumSaslAuthEnabled = quorumSaslAuthEnabled;
    if (!this.quorumSaslAuthEnabled) {
        LOG.debug("Not initializing connection executor as quorum sasl auth is disabled");
        return;
    }
    // init connection executors
    final AtomicInteger threadIndex = new AtomicInteger(1);
    SecurityManager s = System.getSecurityManager();
    final ThreadGroup group = (s != null) ? s.getThreadGroup() : Thread.currentThread().getThreadGroup();
    ThreadFactory daemonThFactory = new ThreadFactory() {

        @Override
        public Thread newThread(Runnable r) {
            Thread t = new Thread(group, r, "QuorumConnectionThread-" + "[myid=" + mySid + "]-" + threadIndex.getAndIncrement());
            return t;
        }
    };
    this.connectionExecutor = new ThreadPoolExecutor(3, quorumCnxnThreadsSize, 60, TimeUnit.SECONDS, new SynchronousQueue<Runnable>(), daemonThFactory);
    this.connectionExecutor.allowCoreThreadTimeOut(true);
}
Also used : 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 14 with SynchronousQueue

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

the class ConnectionTable method createThreadPoolForIO.

private Executor createThreadPoolForIO(boolean conserveSockets) {
    Executor executor = null;
    final ThreadGroup connectionRWGroup = LoggingThreadGroup.createThreadGroup("P2P Reader Threads", logger);
    if (conserveSockets) {
        executor = new Executor() {

            @Override
            public void execute(Runnable command) {
                Thread th = new Thread(connectionRWGroup, command);
                th.setDaemon(true);
                th.start();
            }
        };
    } else {
        BlockingQueue synchronousQueue = new SynchronousQueue();
        ThreadFactory tf = new ThreadFactory() {

            public Thread newThread(final Runnable command) {
                Thread thread = new Thread(connectionRWGroup, command);
                thread.setDaemon(true);
                return thread;
            }
        };
        executor = new ThreadPoolExecutor(1, Integer.MAX_VALUE, READER_POOL_KEEP_ALIVE_TIME, TimeUnit.SECONDS, synchronousQueue, tf);
    }
    return executor;
}
Also used : BlockingQueue(java.util.concurrent.BlockingQueue) ThreadFactory(java.util.concurrent.ThreadFactory) ThreadPoolExecutor(java.util.concurrent.ThreadPoolExecutor) Executor(java.util.concurrent.Executor) SynchronousQueue(java.util.concurrent.SynchronousQueue) LoggingThreadGroup(org.apache.geode.internal.logging.LoggingThreadGroup) ThreadPoolExecutor(java.util.concurrent.ThreadPoolExecutor)

Example 15 with SynchronousQueue

use of java.util.concurrent.SynchronousQueue in project metacat by Netflix.

the class AbstractThriftServer method start.

/**
 * Server initialization.
 *
 * @throws Exception error
 */
public void start() throws Exception {
    log.info("initializing thrift server {}", getServerName());
    final ThreadFactory threadFactory = new ThreadFactoryBuilder().setNameFormat(threadPoolNameFormat).setUncaughtExceptionHandler((t, e) -> log.error("Uncaught exception in thread: {}", t.getName(), e)).build();
    final ExecutorService executorService = new ThreadPoolExecutor(Math.min(2, config.getThriftServerMaxWorkerThreads()), config.getThriftServerMaxWorkerThreads(), 60L, TimeUnit.SECONDS, new SynchronousQueue<>(), threadFactory);
    RegistryUtil.registerThreadPool(registry, threadPoolNameFormat, (ThreadPoolExecutor) executorService);
    final int timeout = config.getThriftServerSocketClientTimeoutInSeconds() * 1000;
    final TServerTransport serverTransport = new TServerSocket(portNumber, timeout);
    startServing(executorService, serverTransport);
}
Also used : ThreadFactoryBuilder(com.google.common.util.concurrent.ThreadFactoryBuilder) Getter(lombok.Getter) SynchronousQueue(java.util.concurrent.SynchronousQueue) ThreadPoolExecutor(java.util.concurrent.ThreadPoolExecutor) NonNull(lombok.NonNull) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) TServer(org.apache.thrift.server.TServer) RegistryUtil(com.netflix.metacat.common.server.util.RegistryUtil) TServerTransport(org.apache.thrift.transport.TServerTransport) TimeUnit(java.util.concurrent.TimeUnit) TServerSocket(org.apache.thrift.transport.TServerSocket) Slf4j(lombok.extern.slf4j.Slf4j) TServerEventHandler(org.apache.thrift.server.TServerEventHandler) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Registry(com.netflix.spectator.api.Registry) TThreadPoolServer(org.apache.thrift.server.TThreadPoolServer) ThreadFactory(java.util.concurrent.ThreadFactory) Config(com.netflix.metacat.common.server.properties.Config) ExecutorService(java.util.concurrent.ExecutorService) TProcessor(org.apache.thrift.TProcessor) TServerSocket(org.apache.thrift.transport.TServerSocket) ThreadFactory(java.util.concurrent.ThreadFactory) ExecutorService(java.util.concurrent.ExecutorService) ThreadFactoryBuilder(com.google.common.util.concurrent.ThreadFactoryBuilder) ThreadPoolExecutor(java.util.concurrent.ThreadPoolExecutor) TServerTransport(org.apache.thrift.transport.TServerTransport)

Aggregations

SynchronousQueue (java.util.concurrent.SynchronousQueue)117 ThreadPoolExecutor (java.util.concurrent.ThreadPoolExecutor)61 ExecutorService (java.util.concurrent.ExecutorService)20 ThreadFactory (java.util.concurrent.ThreadFactory)14 ArrayList (java.util.ArrayList)12 LinkedBlockingQueue (java.util.concurrent.LinkedBlockingQueue)12 IOException (java.io.IOException)9 RejectedExecutionHandler (java.util.concurrent.RejectedExecutionHandler)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