Example usage for java.util.concurrent Executors newCachedThreadPool

List of usage examples for java.util.concurrent Executors newCachedThreadPool

Introduction

In this page you can find the example usage for java.util.concurrent Executors newCachedThreadPool.

Prototype

public static ExecutorService newCachedThreadPool(ThreadFactory threadFactory) 

Source Link

Document

Creates a thread pool that creates new threads as needed, but will reuse previously constructed threads when they are available, and uses the provided ThreadFactory to create new threads when needed.

Usage

From source file:net.sf.jasperreports.engine.fill.ThreadPoolSubreportRunnerFactory.java

protected ExecutorService createThreadExecutor(JRFillContext fillContext) {
    SubreportsThreadFactory threadFactory = new SubreportsThreadFactory(fillContext);
    ExecutorService threadExecutor = Executors.newCachedThreadPool(threadFactory);
    if (log.isDebugEnabled()) {
        log.debug("created subreports thread executor " + threadExecutor + " for "
                + fillContext.getMasterFiller().getJasperReport().getName());
    }//from   w w w.j a v  a2s. co  m
    return threadExecutor;
}

From source file:org.apache.asterix.experiment.client.SpatialQueryGenerator.java

public SpatialQueryGenerator(SpatialQueryGeneratorConfig config) {
    threadPool = Executors.newCachedThreadPool(new ThreadFactory() {

        private final AtomicInteger count = new AtomicInteger();

        @Override// w w w .  j av a  2 s.  com
        public Thread newThread(Runnable r) {
            int tid = count.getAndIncrement();
            Thread t = new Thread(r, "DataGeneratorThread: " + tid);
            t.setDaemon(true);
            return t;
        }
    });

    partitionRangeStart = config.getPartitionRangeStart();
    duration = config.getDuration();
    restHost = config.getRESTHost();
    restPort = config.getRESTPort();
    orchHost = config.getQueryOrchestratorHost();
    orchPort = config.getQueryOrchestratorPort();
    openStreetMapFilePath = config.getOpenStreetMapFilePath();
    isIndexOnlyPlan = config.getIsIndexOnlyPlan();
}

From source file:com.hellblazer.jackal.configuration.ThreadConfig.java

@Bean(name = "communicationsDispatchers")
@Primary//  w  w w  . j  ava 2 s  .  c o  m
@Autowired
public ExecutorService communicationsDispatchers(Identity partitionIdentity) {
    final int id = partitionIdentity.id;
    return Executors.newCachedThreadPool(new ThreadFactory() {
        int count = 0;

        @Override
        public Thread newThread(Runnable target) {
            Thread t = new Thread(target,
                    String.format("Communications Dispatcher[%s] for node[%s]", count++, id));
            t.setDaemon(true);
            t.setUncaughtExceptionHandler(new UncaughtExceptionHandler() {
                @Override
                public void uncaughtException(Thread t, Throwable e) {
                    log.error(String.format("Exception on %s", t), e);
                }
            });
            return t;
        }
    });
}

From source file:io.selendroid.server.SelendroidStandaloneServer.java

public SelendroidStandaloneServer(SelendroidConfiguration configuration)
        throws AndroidSdkException, AndroidDeviceException {
    this.configuration = configuration;
    NamingThreadFactory namingThreadFactory = new NamingThreadFactory(Executors.defaultThreadFactory(),
            "selendroid-standalone-handler");
    webServer = WebServers.createWebServer(Executors.newCachedThreadPool(namingThreadFactory),
            new InetSocketAddress(configuration.getPort()), remoteUri(configuration.getPort()));
    driver = initializeSelendroidServer();
    init();//from ww  w  .  j a  va  2  s . c  o m
}

From source file:io.pivotal.receptor.events.EventDispatcher.java

public EventDispatcher(String url) {
    Assert.hasText(url, "URL is required");
    this.url = url;
    this.backgroundExecutor = Executors
            .newSingleThreadExecutor(new CustomizableThreadFactory("receptor-event-subscriber-"));
    this.dispatchingExecutor = Executors
            .newCachedThreadPool(new CustomizableThreadFactory("receptor-event-dispatcher-"));
}

From source file:com.techcavern.pircbotz.hooks.managers.ThreadedListenerManager.java

/**
 * Configures with default cached thread thread pool.
 *//*w  w  w.  j  av  a2 s.c  o m*/
public ThreadedListenerManager() {
    managerNumber = MANAGER_COUNT.getAndIncrement();
    BasicThreadFactory factory = new BasicThreadFactory.Builder()
            .namingPattern("listenerPool" + managerNumber + "-thread%d").daemon(true).build();
    ThreadPoolExecutor defaultPool = (ThreadPoolExecutor) Executors.newCachedThreadPool(factory);
    defaultPool.allowCoreThreadTimeOut(true);
    this.pool = defaultPool;
}

From source file:com.github.autermann.wps.streaming.ProcessConfiguration.java

public ExecutorService createThreadPool() {
    String nameFormat = "streaming-process-" + getProcessID() + "-%d";
    ThreadFactory threadFactory = new ThreadFactoryBuilder().setNameFormat(nameFormat).build();
    return Executors.newCachedThreadPool(threadFactory);
}

From source file:com.flipkart.phantom.runtime.impl.server.netty.TCPNettyServer.java

/**
 * Interface method implementation. Creates server and worker thread pools if required and then calls {@link #afterPropertiesSet()} on the super class
 * @see org.springframework.beans.factory.InitializingBean#afterPropertiesSet()
 *///from  ww  w .  ja  v  a  2  s . co  m
public void afterPropertiesSet() throws Exception {
    if (this.getServerExecutors() == null) { // no executors have been set for server listener
        if (this.getServerPoolSize() != TCPNettyServer.INVALID_POOL_SIZE) { // thread pool size has been set. create and use a fixed thread pool
            this.setServerExecutors(Executors.newFixedThreadPool(this.getServerPoolSize(),
                    new NamedThreadFactory("TCPServer-Listener")));
        } else { // default behavior of creating and using a cached thread pool
            this.setServerExecutors(
                    Executors.newCachedThreadPool(new NamedThreadFactory("TCPServer-Listener")));
        }
    }
    if (this.getWorkerExecutors() == null) { // no executors have been set for workers
        if (this.getWorkerPoolSize() != TCPNettyServer.INVALID_POOL_SIZE) { // thread pool size has been set. create and use a fixed thread pool
            this.setWorkerExecutors(Executors.newFixedThreadPool(this.getWorkerPoolSize(),
                    new NamedThreadFactory("TCPServer-Worker")));
        } else { // default behavior of creating and using a cached thread pool
            this.setWorkerExecutors(Executors.newCachedThreadPool(new NamedThreadFactory("TCPServer-Worker")));
        }
    }
    super.afterPropertiesSet();
}

From source file:com.mgmtp.perfload.core.test.comp.ComponentTest.java

@Test
public void testLoadProfile() throws Exception {
    XmlConfigReader confReader = new XmlConfigReader(new File("src/test/resources"),
            "testplan_loadprofile.xml");
    TestplanConfig config = confReader.readConfig();
    StatusTransformer transformer = new FileStatusTransformer(config.getTotalThreadCount(),
            new File("target", "ltStatus.txt"), new File("target", "loadprofile.txt"), "UTF-8");
    LtConsole console = new LtConsole(config, Executors.newCachedThreadPool(new DaemonThreadFactory()),
            transformer, new LtMetaInfoHandler(), asList(new Daemon(1, "localhost", DAEMON_PORT)), false, false,
            300000L);/*w  w  w.  j a  v  a2 s. c  o  m*/
    console.execute();

    assertEquals(console.isTestSuccessful(), true);
}

From source file:com.aipo.container.gadgets.AipoGadgetsGuiceModule.java

/** {@inheritDoc} */
@Override// w  ww  . j  a v a  2 s.com
protected void configure() {

    bind(LockedDomainService.class).to(AipoHashLockedDomainService.class).in(Scopes.SINGLETON);
    bind(JsonRpcHandler.class).to(AipoJsonRpcHandler.class);
    bind(RpcServiceLookup.class).to(AipoRpcServiceLookup.class);

    final ExecutorService service = Executors.newCachedThreadPool(DAEMON_THREAD_FACTORY);
    bind(ExecutorService.class).toInstance(service);
    bind(ExecutorService.class).annotatedWith(Names.named("shindig.concat.executor")).toInstance(service);

    Runtime.getRuntime().addShutdownHook(new Thread() {
        @Override
        public void run() {
            service.shutdownNow();
        }
    });

    install(new AipoParseModule());
    install(new PreloadModule());
    install(new RenderModule());
    install(new AipoRewriteModule());
    install(new SubstituterModule());
    install(new TemplateModule());
    install(new AipoUriModule());

    // bind(Long.class).annotatedWith(Names.named("org.apache.shindig.serviceExpirationDurationMinutes")).toInstance(60l);

    // We perform static injection on HttpResponse for cache TTLs.
    requestStaticInjection(HttpResponse.class);

    registerGadgetHandlers();
    registerConfigContributors();
    registerFeatureHandlers();
}