use of java.util.concurrent.SynchronousQueue in project lucene-solr by apache.
the class UnloadDistributedZkTest method testUnloadLotsOfCores.
private void testUnloadLotsOfCores() throws Exception {
SolrClient client = clients.get(2);
String url3 = getBaseUrl(client);
try (final HttpSolrClient adminClient = getHttpSolrClient(url3)) {
adminClient.setConnectionTimeout(15000);
adminClient.setSoTimeout(60000);
int cnt = atLeast(3);
ThreadPoolExecutor executor = new ExecutorUtil.MDCAwareThreadPoolExecutor(0, Integer.MAX_VALUE, 5, TimeUnit.SECONDS, new SynchronousQueue<Runnable>(), new DefaultSolrThreadFactory("testExecutor"));
try {
// create the cores
createCores(adminClient, executor, "multiunload", 2, cnt);
} finally {
ExecutorUtil.shutdownAndAwaitTermination(executor);
}
executor = new ExecutorUtil.MDCAwareThreadPoolExecutor(0, Integer.MAX_VALUE, 5, TimeUnit.SECONDS, new SynchronousQueue<Runnable>(), new DefaultSolrThreadFactory("testExecutor"));
try {
for (int j = 0; j < cnt; j++) {
final int freezeJ = j;
executor.execute(() -> {
Unload unloadCmd = new Unload(true);
unloadCmd.setCoreName("multiunload" + freezeJ);
try {
adminClient.request(unloadCmd);
} catch (SolrServerException | IOException e) {
throw new RuntimeException(e);
}
});
Thread.sleep(random().nextInt(50));
}
} finally {
ExecutorUtil.shutdownAndAwaitTermination(executor);
}
}
}
use of java.util.concurrent.SynchronousQueue in project hazelcast by hazelcast.
the class CachedExecutorServiceDelegateTest method setup.
@Before
public void setup() {
cachedExecutorService = new NamedThreadPoolExecutor("test", 0, Integer.MAX_VALUE, 60L, TimeUnit.SECONDS, new SynchronousQueue<Runnable>(), Executors.defaultThreadFactory());
ExecutionService executionService = mock(ExecutionService.class);
when(executionService.getExecutor(ExecutionService.ASYNC_EXECUTOR)).thenReturn(cachedExecutorService);
nodeEngine = mock(NodeEngine.class);
when(nodeEngine.getExecutionService()).thenReturn(executionService);
}
use of java.util.concurrent.SynchronousQueue in project hadoop by apache.
the class ErasureCodingWorker method initializeStripedReadThreadPool.
private void initializeStripedReadThreadPool(int num) {
LOG.debug("Using striped reads; pool threads={}", num);
stripedReadPool = new ThreadPoolExecutor(1, num, 60, TimeUnit.SECONDS, new SynchronousQueue<Runnable>(), new Daemon.DaemonFactory() {
private final AtomicInteger threadIndex = new AtomicInteger(0);
@Override
public Thread newThread(Runnable r) {
Thread t = super.newThread(r);
t.setName("stripedRead-" + threadIndex.getAndIncrement());
return t;
}
}, new ThreadPoolExecutor.CallerRunsPolicy() {
@Override
public void rejectedExecution(Runnable runnable, ThreadPoolExecutor e) {
LOG.info("Execution for striped reading rejected, " + "Executing in current thread");
// will run in the current thread
super.rejectedExecution(runnable, e);
}
});
stripedReadPool.allowCoreThreadTimeOut(true);
}
use of java.util.concurrent.SynchronousQueue in project camel by apache.
the class ThreadsRejectedExecutionTest method testThreadsRejectedExecution.
public void testThreadsRejectedExecution() throws Exception {
context.addRoutes(new RouteBuilder() {
@Override
public void configure() throws Exception {
// use a custom pool which rejects any new tasks while currently in progress
// this should force the ThreadsProcessor to run the tasks itself
ExecutorService pool = new ThreadPoolExecutor(1, 1, 0, TimeUnit.SECONDS, new SynchronousQueue<Runnable>());
from("seda:start").to("log:before").threads().executorService(pool).delay(1000).to("log:after").to("mock:result");
}
});
context.start();
getMockEndpoint("mock:result").expectedMessageCount(3);
template.sendBody("seda:start", "Hello World");
template.sendBody("seda:start", "Hi World");
template.sendBody("seda:start", "Bye World");
assertMockEndpointsSatisfied();
}
use of java.util.concurrent.SynchronousQueue in project camel by apache.
the class ThreadsRejectedExecutionTest method testThreadsRejectedExecutionCallerNotRuns.
public void testThreadsRejectedExecutionCallerNotRuns() throws Exception {
context.addRoutes(new RouteBuilder() {
@Override
public void configure() throws Exception {
// use a custom pool which rejects any new tasks while currently in progress
// this should force the ThreadsProcessor to run the tasks itself
ExecutorService pool = new ThreadPoolExecutor(1, 1, 0, TimeUnit.SECONDS, new SynchronousQueue<Runnable>());
from("seda:start").to("log:before").threads().executorService(pool).callerRunsWhenRejected(false).delay(1000).to("log:after").to("mock:result");
}
});
context.start();
MockEndpoint mock = getMockEndpoint("mock:result");
mock.expectedMessageCount(3);
// wait at most 5 seconds
mock.setResultWaitTime(5000);
template.sendBody("seda:start", "Hello World");
template.sendBody("seda:start", "Hi World");
template.sendBody("seda:start", "Bye World");
// should not be possible to route all 3
mock.assertIsNotSatisfied();
// only 1 should arrive
assertEquals(1, mock.getReceivedCounter());
}
Aggregations