use of java.util.concurrent.SynchronousQueue in project rt.equinox.framework by eclipse.
the class EquinoxContainerAdaptor method createLazyExecutorCreator.
private Callable<Executor> createLazyExecutorCreator(EquinoxConfiguration config) {
String threadCntProp = config.getConfiguration(EquinoxConfiguration.PROP_RESOLVER_THREAD_COUNT);
int threadCntTmp;
try {
threadCntTmp = threadCntProp == null ? -1 : Integer.parseInt(threadCntProp);
} catch (NumberFormatException e) {
threadCntTmp = -1;
}
// use the number of processors - 1 because we use the current thread when rejected
final int maxThreads = threadCntTmp <= 0 ? Math.max(Runtime.getRuntime().availableProcessors() - 1, 1) : threadCntTmp;
return new Callable<Executor>() {
@Override
public Executor call() throws Exception {
if (maxThreads == 1) {
return new Executor() {
@Override
public void execute(Runnable command) {
command.run();
}
};
}
// Always want to go to zero threads when idle
int coreThreads = 0;
// idle timeout; make it short to get rid of threads quickly after resolve
int idleTimeout = 10;
// use sync queue to force thread creation
BlockingQueue<Runnable> queue = new SynchronousQueue<>();
// try to name the threads with useful name
ThreadFactory threadFactory = new ThreadFactory() {
@Override
public Thread newThread(Runnable r) {
// $NON-NLS-1$
Thread t = new Thread(r, "Resolver thread - " + EquinoxContainerAdaptor.this.toString());
t.setDaemon(true);
return t;
}
};
// use a rejection policy that simply runs the task in the current thread once the max threads is reached
RejectedExecutionHandler rejectHandler = new RejectedExecutionHandler() {
@Override
public void rejectedExecution(Runnable r, ThreadPoolExecutor exe) {
r.run();
}
};
return new ThreadPoolExecutor(coreThreads, maxThreads, idleTimeout, TimeUnit.SECONDS, queue, threadFactory, rejectHandler);
}
};
}
use of java.util.concurrent.SynchronousQueue in project dubbo by alibaba.
the class CachedThreadPool 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, Integer.MAX_VALUE);
int queues = url.getParameter(Constants.QUEUES_KEY, Constants.DEFAULT_QUEUES);
int alive = url.getParameter(Constants.ALIVE_KEY, Constants.DEFAULT_ALIVE);
return new ThreadPoolExecutor(cores, threads, alive, 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 CommandHelper by EngineHub.
the class ExecutionQueue method startQueue.
private synchronized void startQueue(final DaemonManager dm, final String queue) {
synchronized (locks.get(queue)) {
if (!isRunning(queue)) {
// We need to create a new thread
runningQueues.put(queue, true);
if (dm != null) {
dm.activateThread(null);
}
if (service == null) {
service = new ThreadPoolExecutor(0, Integer.MAX_VALUE, 50L, TimeUnit.MILLISECONDS, new SynchronousQueue<Runnable>(), threadFactory);
}
service.submit(new Runnable() {
@Override
public void run() {
try {
pumpQueue(queue);
} catch (RuntimeException t) {
if (uncaughtExceptionHandler != null) {
uncaughtExceptionHandler.uncaughtException(Thread.currentThread(), t);
} else {
StreamUtils.GetSystemErr().println("The queue \"" + queue + "\" threw an exception, and it was not handled.");
t.printStackTrace(StreamUtils.GetSystemErr());
}
} finally {
if (dm != null) {
dm.deactivateThread(null);
}
}
}
});
}
}
}
use of java.util.concurrent.SynchronousQueue in project cdap by caskdata.
the class HBaseMetricsTable method initializeV3Vars.
private void initializeV3Vars(CConfiguration cConf, DatasetSpecification spec) {
boolean isV3Table = spec.getName().contains("v3");
this.scanExecutor = null;
this.rowKeyDistributor = null;
if (isV3Table) {
RejectedExecutionHandler callerRunsPolicy = new RejectedExecutionHandler() {
@Override
public void rejectedExecution(Runnable r, ThreadPoolExecutor executor) {
REJECTION_LOG.info("No more threads in the HBase scan thread pool. Consider increase {}. Performing scan in caller thread {}", Constants.Metrics.METRICS_HBASE_MAX_SCAN_THREADS, Thread.currentThread().getName());
// Runs it from the caller thread
if (!executor.isShutdown()) {
r.run();
}
}
};
int maxScanThread = cConf.getInt(Constants.Metrics.METRICS_HBASE_MAX_SCAN_THREADS);
// Creates a executor that will shrink to 0 threads if left idle
// Uses daemon thread, hence no need to worry about shutdown
// When all threads are busy, use the caller thread to execute
this.scanExecutor = new ThreadPoolExecutor(0, maxScanThread, 60L, TimeUnit.SECONDS, new SynchronousQueue<Runnable>(), Threads.createDaemonThreadFactory("metrics-hbase-scanner-%d"), callerRunsPolicy);
this.rowKeyDistributor = new RowKeyDistributorByHashPrefix(new RowKeyDistributorByHashPrefix.OneByteSimpleHash(spec.getIntProperty(Constants.Metrics.METRICS_HBASE_TABLE_SPLITS, 16)));
}
}
use of java.util.concurrent.SynchronousQueue in project activemq-artemis by apache.
the class JournalImpl method start.
@Override
public synchronized void start() {
if (state != JournalState.STOPPED) {
throw new IllegalStateException("Journal " + this + " is not stopped, state is " + state);
}
if (providedIOThreadPool == null) {
ThreadFactory factory = AccessController.doPrivileged(new PrivilegedAction<ThreadFactory>() {
@Override
public ThreadFactory run() {
return new ActiveMQThreadFactory("ArtemisIOThread", true, JournalImpl.class.getClassLoader());
}
});
threadPool = new ThreadPoolExecutor(0, Integer.MAX_VALUE, 60L, TimeUnit.SECONDS, new SynchronousQueue(), factory);
ioExecutorFactory = new OrderedExecutorFactory(threadPool);
} else {
ioExecutorFactory = providedIOThreadPool;
}
filesExecutor = ioExecutorFactory.getExecutor();
compactorExecutor = ioExecutorFactory.getExecutor();
appendExecutor = ioExecutorFactory.getExecutor();
filesRepository.setExecutor(filesExecutor);
fileFactory.start();
setJournalState(JournalState.STARTED);
}
Aggregations