Search in sources :

Example 56 with SynchronousQueue

use of java.util.concurrent.SynchronousQueue in project jPOS by jpos.

the class TSpacePerformanceTest method testStolenEntryAtNotify.

@Disabled("Remove it when TSpace can pass it")
@Test
public void testStolenEntryAtNotify() 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 WriteSpaceWithNotifyReadTask("WriteTask-" + i));
    // Threads which may stole entries
    for (int i = 0; i < size; i++) es.execute(new ReadSpaceTask("WriteTask-" + i));
    assertNull(sp2.in("lost-entry", 200), "Detected stolen entry at notify");
    es.shutdownNow();
// es.awaitTermination(5, TimeUnit.SECONDS);
}
Also used : SynchronousQueue(java.util.concurrent.SynchronousQueue) ExecutorService(java.util.concurrent.ExecutorService) ThreadPoolExecutor(java.util.concurrent.ThreadPoolExecutor) Test(org.junit.jupiter.api.Test) Disabled(org.junit.jupiter.api.Disabled)

Example 57 with SynchronousQueue

use of java.util.concurrent.SynchronousQueue in project jPOS by jpos.

the class TSpacePerformanceTest method testReadPerformance.

@Test
public void testReadPerformance() throws Throwable {
    int size = 10;
    ExecutorService es = new ThreadPoolExecutor(size, Integer.MAX_VALUE, 30, TimeUnit.SECONDS, new SynchronousQueue());
    ((ThreadPoolExecutor) es).prestartAllCoreThreads();
    for (int i = 0; i < size; i++) es.execute(new WriteSpaceTask("PerformTask-" + i));
    ISOUtil.sleep(500);
    printAvg(t1, "Avg. write: ");
    for (int i = 0; i < size; i++) es.execute(new ReadSpaceTask("PerformTask-" + i));
    ISOUtil.sleep(500);
    es.shutdown();
    printAvg(t2, "Avg. read : ");
}
Also used : SynchronousQueue(java.util.concurrent.SynchronousQueue) ExecutorService(java.util.concurrent.ExecutorService) ThreadPoolExecutor(java.util.concurrent.ThreadPoolExecutor) Test(org.junit.jupiter.api.Test)

Example 58 with SynchronousQueue

use of java.util.concurrent.SynchronousQueue in project jPOS by jpos.

the class OneShotChannelAdaptorMK2 method startService.

public void startService() {
    setRealm(getName());
    cnt = new AtomicInteger(0);
    threadPool = new ThreadPoolExecutor(1, maxConnections, 10, TimeUnit.SECONDS, new SynchronousQueue<Runnable>());
    new Thread(this).start();
    checkTimer = Executors.newScheduledThreadPool(1);
    checkTimer.scheduleAtFixedRate(new CheckChannelTask(), 0L, checkInterval, TimeUnit.MILLISECONDS);
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) SynchronousQueue(java.util.concurrent.SynchronousQueue) ThreadPoolExecutor(java.util.concurrent.ThreadPoolExecutor)

Example 59 with SynchronousQueue

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);
}
Also used : ThreadFactoryBuilder(com.google.common.util.concurrent.ThreadFactoryBuilder) Getter(lombok.Getter) SynchronousQueue(java.util.concurrent.SynchronousQueue) ThreadPoolExecutor(java.util.concurrent.ThreadPoolExecutor) NonNull(lombok.NonNull) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) TServer(org.apache.thrift.server.TServer) RegistryUtil(com.netflix.metacat.common.server.util.RegistryUtil) TServerTransport(org.apache.thrift.transport.TServerTransport) TimeUnit(java.util.concurrent.TimeUnit) TServerSocket(org.apache.thrift.transport.TServerSocket) Slf4j(lombok.extern.slf4j.Slf4j) TServerEventHandler(org.apache.thrift.server.TServerEventHandler) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Registry(com.netflix.spectator.api.Registry) TThreadPoolServer(org.apache.thrift.server.TThreadPoolServer) ThreadFactory(java.util.concurrent.ThreadFactory) Config(com.netflix.metacat.common.server.properties.Config) ExecutorService(java.util.concurrent.ExecutorService) TProcessor(org.apache.thrift.TProcessor) TServerSocket(org.apache.thrift.transport.TServerSocket) ThreadFactory(java.util.concurrent.ThreadFactory) ExecutorService(java.util.concurrent.ExecutorService) ThreadFactoryBuilder(com.google.common.util.concurrent.ThreadFactoryBuilder) ThreadPoolExecutor(java.util.concurrent.ThreadPoolExecutor) TServerTransport(org.apache.thrift.transport.TServerTransport)

Example 60 with SynchronousQueue

use of java.util.concurrent.SynchronousQueue in project verify-hub by alphagov.

the class PrometheusClient method createMatchingServiceHealthCheckMetrics.

public void createMatchingServiceHealthCheckMetrics() {
    final PrometheusClientServiceConfiguration configuration = samlSoapProxyConfiguration.getMatchingServiceHealthCheckServiceConfiguration();
    if (configuration.getEnable()) {
        Gauge healthStatusGauge = Gauge.build(VERIFY_SAML_SOAP_PROXY_MSA_HEALTH_STATUS, VERIFY_SAML_SOAP_PROXY_MSA_HEALTH_STATUS_HELP).labelNames("matchingService").register();
        Gauge healthStatusLastUpdatedGauge = Gauge.build(VERIFY_SAML_SOAP_PROXY_MSA_HEALTH_STATUS_LAST_UPDATED, VERIFY_SAML_SOAP_PROXY_MSA_HEALTH_STATUS_LAST_UPDATED_HELP).labelNames("matchingService").register();
        MatchingServiceInfoMetric infoMetric = new MatchingServiceInfoMetric().register();
        ExecutorService matchingServiceHealthCheckTaskManager = environment.lifecycle().executorService(MSA_HEALTH_CHECK_TASK_MANAGER).threadFactory(new ThreadFactoryBuilder().setNameFormat(MSA_HEALTH_CHECK_TASK_MANAGER).setDaemon(USE_DAEMON_THREADS).build()).minThreads(configuration.getMinNumOfThreads()).maxThreads(configuration.getMaxNumOfThreads()).keepAliveTime(configuration.getKeepAliveTime()).workQueue(new SynchronousQueue<>()).build();
        MatchingServiceHealthCheckService matchingServiceHealthCheckService = new MatchingServiceHealthCheckService(matchingServiceHealthCheckTaskManager, samlSoapProxyConfiguration.getHealthCheckSoapHttpClient().getTimeout(), matchingServiceConfigProxy, matchingServiceHealthChecker, healthStatusGauge, healthStatusLastUpdatedGauge, infoMetric);
        createScheduledExecutorService(configuration, VERIFY_SAML_SOAP_PROXY_MSA_HEALTH_STATUS, matchingServiceHealthCheckService);
    }
}
Also used : MatchingServiceInfoMetric(uk.gov.ida.hub.samlsoapproxy.service.MatchingServiceInfoMetric) SynchronousQueue(java.util.concurrent.SynchronousQueue) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) ExecutorService(java.util.concurrent.ExecutorService) ThreadFactoryBuilder(com.google.common.util.concurrent.ThreadFactoryBuilder) PrometheusClientServiceConfiguration(uk.gov.ida.hub.samlsoapproxy.config.PrometheusClientServiceConfiguration) MatchingServiceHealthCheckService(uk.gov.ida.hub.samlsoapproxy.service.MatchingServiceHealthCheckService) Gauge(io.prometheus.client.Gauge)

Aggregations

SynchronousQueue (java.util.concurrent.SynchronousQueue)120 ThreadPoolExecutor (java.util.concurrent.ThreadPoolExecutor)64 ExecutorService (java.util.concurrent.ExecutorService)21 ThreadFactory (java.util.concurrent.ThreadFactory)15 LinkedBlockingQueue (java.util.concurrent.LinkedBlockingQueue)13 ArrayList (java.util.ArrayList)12 RejectedExecutionHandler (java.util.concurrent.RejectedExecutionHandler)10 IOException (java.io.IOException)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