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));
}
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));
}
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);
}
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;
}
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);
}
Aggregations