Search in sources :

Example 6 with SynchronousQueue

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);
        }
    }
}
Also used : SolrServerException(org.apache.solr.client.solrj.SolrServerException) DefaultSolrThreadFactory(org.apache.solr.util.DefaultSolrThreadFactory) IOException(java.io.IOException) ExecutorUtil(org.apache.solr.common.util.ExecutorUtil) HttpSolrClient(org.apache.solr.client.solrj.impl.HttpSolrClient) Unload(org.apache.solr.client.solrj.request.CoreAdminRequest.Unload) SolrClient(org.apache.solr.client.solrj.SolrClient) HttpSolrClient(org.apache.solr.client.solrj.impl.HttpSolrClient) SynchronousQueue(java.util.concurrent.SynchronousQueue) ThreadPoolExecutor(java.util.concurrent.ThreadPoolExecutor)

Example 7 with SynchronousQueue

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);
}
Also used : NodeEngine(com.hazelcast.spi.NodeEngine) SynchronousQueue(java.util.concurrent.SynchronousQueue) ExecutionService(com.hazelcast.spi.ExecutionService) Before(org.junit.Before)

Example 8 with SynchronousQueue

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);
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) SynchronousQueue(java.util.concurrent.SynchronousQueue) ThreadPoolExecutor(java.util.concurrent.ThreadPoolExecutor)

Example 9 with SynchronousQueue

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();
}
Also used : RouteBuilder(org.apache.camel.builder.RouteBuilder) SynchronousQueue(java.util.concurrent.SynchronousQueue) ExecutorService(java.util.concurrent.ExecutorService) ThreadPoolExecutor(java.util.concurrent.ThreadPoolExecutor)

Example 10 with SynchronousQueue

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());
}
Also used : RouteBuilder(org.apache.camel.builder.RouteBuilder) MockEndpoint(org.apache.camel.component.mock.MockEndpoint) SynchronousQueue(java.util.concurrent.SynchronousQueue) ExecutorService(java.util.concurrent.ExecutorService) ThreadPoolExecutor(java.util.concurrent.ThreadPoolExecutor)

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