use of java.util.concurrent.SynchronousQueue in project jPOS by jpos.
the class TSpacePerformanceTest method testDeadLockWithNotify.
@Test
public void testDeadLockWithNotify() throws Throwable {
int size = 10;
final ExecutorService es = new ThreadPoolExecutor(size * 2, Integer.MAX_VALUE, 30, TimeUnit.SECONDS, new SynchronousQueue());
((ThreadPoolExecutor) es).prestartAllCoreThreads();
for (int i = 0; i < size; i++) es.execute(new WriteSpaceWithNotifyTask("WriteTask1-" + i, sp1, sp2));
for (int i = 0; i < size; i++) es.execute(new WriteSpaceWithNotifyTask("WriteTask2-" + i, sp2, sp1));
long stamp = System.currentTimeMillis();
while (((ThreadPoolExecutor) es).getActiveCount() > 0) {
if (System.currentTimeMillis() - stamp < 10000) {
ISOUtil.sleep(100);
continue;
}
es.shutdownNow();
fail("Probably death-lock detected");
return;
}
printAvg(t1, "Avg. write: ");
// es.shutdown();
es.shutdownNow();
es.awaitTermination(5, TimeUnit.SECONDS);
}
use of java.util.concurrent.SynchronousQueue in project rt.equinox.framework by eclipse.
the class TestModuleContainer method testUsesTimeout.
// DISABLE see bug 498064 @Test
public void testUsesTimeout() throws BundleException {
// Always want to go to zero threads when idle
int coreThreads = 0;
// use the number of processors - 1 because we use the current thread when rejected
int maxThreads = Math.max(Runtime.getRuntime().availableProcessors() - 1, 1);
// idle timeout; make it short to get rid of threads quickly after resolve
int idleTimeout = 5;
// use sync queue to force thread creation
BlockingQueue<Runnable> queue = new SynchronousQueue<Runnable>();
// 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 - UNIT TEST");
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();
}
};
ExecutorService executor = new ThreadPoolExecutor(coreThreads, maxThreads, idleTimeout, TimeUnit.SECONDS, queue, threadFactory, rejectHandler);
ScheduledExecutorService timeoutExecutor = new ScheduledThreadPoolExecutor(1);
Map<String, String> configuration = new HashMap<String, String>();
configuration.put(EquinoxConfiguration.PROP_RESOLVER_BATCH_TIMEOUT, "5000");
Map<String, String> debugOpts = Collections.emptyMap();
DummyContainerAdaptor adaptor = new DummyContainerAdaptor(new DummyCollisionHook(false), configuration, new DummyResolverHookFactory(), new DummyDebugOptions(debugOpts));
adaptor.setResolverExecutor(executor);
adaptor.setTimeoutExecutor(timeoutExecutor);
ModuleContainer container = adaptor.getContainer();
for (int i = 1; i <= 1000; i++) {
for (Map<String, String> manifest : getUsesTimeoutManifests("test" + i)) {
installDummyModule(manifest, manifest.get(Constants.BUNDLE_SYMBOLICNAME), container);
}
}
ResolutionReport report = container.resolve(container.getModules(), true);
Assert.assertNull("Found resolution errors.", report.getResolutionException());
for (Module module : container.getModules()) {
Assert.assertEquals("Wrong state of module: " + module, State.RESOLVED, module.getState());
}
executor.shutdown();
timeoutExecutor.shutdown();
System.gc();
System.gc();
System.gc();
}
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 Payara by payara.
the class EjbContainerUtilImpl method createThreadPoolExecutor.
private ThreadPoolExecutor createThreadPoolExecutor(String poolName) {
ThreadPoolExecutor result = null;
String val = ejbContainer.getPropertyValue(RuntimeTagNames.THREAD_CORE_POOL_SIZE);
int corePoolSize = val != null ? Integer.parseInt(val.trim()) : EjbContainer.DEFAULT_THREAD_CORE_POOL_SIZE;
val = ejbContainer.getPropertyValue(RuntimeTagNames.THREAD_MAX_POOL_SIZE);
int maxPoolSize = val != null ? Integer.parseInt(val.trim()) : EjbContainer.DEFAULT_THREAD_MAX_POOL_SIZE;
val = ejbContainer.getPropertyValue(RuntimeTagNames.THREAD_KEEP_ALIVE_SECONDS);
long keepAliveSeconds = val != null ? Long.parseLong(val.trim()) : EjbContainer.DEFAULT_THREAD_KEEP_ALIVE_SECONDS;
val = ejbContainer.getPropertyValue(RuntimeTagNames.THREAD_QUEUE_CAPACITY);
int queueCapacity = val != null ? Integer.parseInt(val.trim()) : EjbContainer.DEFAULT_THREAD_QUEUE_CAPACITY;
val = ejbContainer.getPropertyValue(RuntimeTagNames.ALLOW_CORE_THREAD_TIMEOUT);
boolean allowCoreThreadTimeout = val != null ? Boolean.parseBoolean(val.trim()) : EjbContainer.DEFAULT_ALLOW_CORE_THREAD_TIMEOUT;
val = ejbContainer.getPropertyValue(RuntimeTagNames.PRESTART_ALL_CORE_THREADS);
boolean preStartAllCoreThreads = val != null ? Boolean.parseBoolean(val.trim()) : EjbContainer.DEFAULT_PRESTART_ALL_CORE_THREADS;
BlockingQueue workQueue = queueCapacity > 0 ? new LinkedBlockingQueue<Runnable>(queueCapacity) : new SynchronousQueue(true);
// PAYARA-405 validates attributes of the thread pool to ensure no problems
if (corePoolSize < 0) {
_logger.log(Level.WARNING, "Core Pool Size configured to be less than 0. Resetting to 0");
corePoolSize = 0;
}
if (maxPoolSize < 1) {
_logger.log(Level.WARNING, "Max Pool Size configured to be less than 1. Resetting to 1");
maxPoolSize = 1;
}
if (corePoolSize > maxPoolSize) {
_logger.log(Level.WARNING, "Core Pool Size configured to be greater than maxPoolSize. Resetting to maxPoolSize {0}", maxPoolSize);
corePoolSize = maxPoolSize;
}
if (keepAliveSeconds < 0) {
_logger.log(Level.WARNING, "Keep Alive Seconds configured to be less than 0. Resetting to 0");
keepAliveSeconds = 0;
}
result = new EjbThreadPoolExecutor(corePoolSize, maxPoolSize, keepAliveSeconds, workQueue, poolName);
if (allowCoreThreadTimeout) {
result.allowCoreThreadTimeOut(true);
}
if (preStartAllCoreThreads) {
result.prestartAllCoreThreads();
}
if (_logger.isLoggable(Level.FINE)) {
_logger.log(Level.FINE, "Created {0}", result.toString());
}
return result;
}
use of java.util.concurrent.SynchronousQueue in project Payara by payara.
the class PayaraExecutorService method initialiseThreadPools.
private void initialiseThreadPools() {
int threadPoolExecutorQueueSize = Integer.valueOf(payaraExecutorServiceConfiguration.getThreadPoolExecutorQueueSize());
if (threadPoolExecutorQueueSize > 0) {
threadPoolExecutor = new ThreadPoolExecutor(Integer.valueOf(payaraExecutorServiceConfiguration.getThreadPoolExecutorCorePoolSize()), Integer.valueOf(payaraExecutorServiceConfiguration.getThreadPoolExecutorMaxPoolSize()), Integer.valueOf(payaraExecutorServiceConfiguration.getThreadPoolExecutorKeepAliveTime()), TimeUnit.valueOf(payaraExecutorServiceConfiguration.getThreadPoolExecutorKeepAliveTimeUnit()), new LinkedBlockingQueue<>(threadPoolExecutorQueueSize), (Runnable r) -> new Thread(r, "payara-executor-service-task"));
} else {
threadPoolExecutor = new ThreadPoolExecutor(Integer.valueOf(payaraExecutorServiceConfiguration.getThreadPoolExecutorCorePoolSize()), Integer.valueOf(payaraExecutorServiceConfiguration.getThreadPoolExecutorMaxPoolSize()), Integer.valueOf(payaraExecutorServiceConfiguration.getThreadPoolExecutorKeepAliveTime()), TimeUnit.valueOf(payaraExecutorServiceConfiguration.getThreadPoolExecutorKeepAliveTimeUnit()), new SynchronousQueue<>(), (Runnable r) -> new Thread(r, "payara-executor-service-task"));
}
scheduledThreadPoolExecutor = new ScheduledThreadPoolExecutor(Integer.valueOf(payaraExecutorServiceConfiguration.getScheduledThreadPoolExecutorCorePoolSize()));
}
Aggregations