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() 

Source Link

Document

Creates a thread pool that creates new threads as needed, but will reuse previously constructed threads when they are available.

Usage

From source file:jp.realglobe.util.uploader.DelayedWatcherTest.java

/**
 * @throws Exception /*from  www .  j a  v  a  2s . c  o  m*/
 */
@Before
public void setUp() throws Exception {
    this.directory = Files.createTempDirectory(DelayedWatcherTest.class.getSimpleName());
    this.executor = Executors.newCachedThreadPool();
    this.detected = new LinkedBlockingQueue<>();
}

From source file:com.miserablemind.api.consumer.tradeking.api.impl.StreamDispatcher.java

public StreamDispatcher(Queue<String> queue, List<StreamListener> listeners) {
    this.queue = queue;
    this.listeners = listeners;
    pool = Executors.newCachedThreadPool();
    objectMapper = new ObjectMapper();
    objectMapper.registerModule(new JodaModule());

    objectMapper.addMixInAnnotations(TradeKingObject.class, TradeKingKObjectMixIn.class);
    objectMapper.addMixInAnnotations(StreamQuoteEvent.class, StreamQuoteMixIn.class);
    objectMapper.addMixInAnnotations(StreamTradeEvent.class, StreamTradeMixIn.class);
    objectMapper.configure(DeserializationFeature.UNWRAP_ROOT_VALUE, true);

    active = new AtomicBoolean(true);
}

From source file:com.amazonaws.services.kinesis.multilang.MessageWriterTest.java

@Before
public void setup() {
    stream = Mockito.mock(OutputStream.class);
    messageWriter = new MessageWriter().initialize(stream, shardId, new ObjectMapper(),
            Executors.newCachedThreadPool());
}

From source file:com.amazonaws.devicefarm.DeviceFarmUploader.java

public DeviceFarmUploader(final AWSDeviceFarmClient api, final Logger logger) {
    this.api = api;
    this.logger = logger;
    this.uploadExecutor = Executors.newCachedThreadPool();
}

From source file:com.apress.prospringintegration.concurrency.taskexecutorexample.TaskExecutorExampleConfiguration.java

@Bean
public TaskExecutorAdapter taskExecutorAdapter() {
    return new TaskExecutorAdapter(Executors.newCachedThreadPool());
}

From source file:be.solidx.hot.test.data.jdbc.TestJsCollectionApi.java

@Test
public void testSync() throws Exception {
    JSScriptExecutor executor = new JSScriptExecutor();
    Map<String, Object> context = new HashMap<>();
    context.put("db", db);
    context.put("adb", new JSAsyncDB(db, Executors.newCachedThreadPool(), Executors.newSingleThreadExecutor(),
            executor.getGlobalScope()));

    executor.setGlobalScopeScripts(Arrays.asList("/js/qunit-1.14.js"));
    Script<org.mozilla.javascript.Script> script = new Script<>(
            IOUtils.toByteArray(getClass().getResourceAsStream("/be/solidx/hot/test/data/jdbc/scripts/db.js")),
            "db.js");
    StringWriter out = new StringWriter();
    executor.execute(script, context, out);

    Assert.assertFalse(out.toString().contains("FAIL"));
}

From source file:net.sf.appstatus.demo.batch.LaunchClassicBatchSampleServlet.java

@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

    // launch the batch
    ExecutorService executorService = Executors.newCachedThreadPool();

    BatchSample batch = (BatchSample) WebApplicationContextUtils
            .getRequiredWebApplicationContext(getServletContext()).getBean("batch");
    executorService.execute(batch);//from www. jav a  2 s.  c om

    BatchSample2 batch2 = (BatchSample2) WebApplicationContextUtils
            .getRequiredWebApplicationContext(getServletContext()).getBean("batch2");
    executorService.execute(batch2);

    ServletOutputStream os = resp.getOutputStream();

    os.write("<html><head".getBytes(ENCODING));
    os.write("<body>".getBytes(ENCODING));
    os.write("<h1>Ok</h1>".getBytes(ENCODING));
    os.write("</body></html>".getBytes(ENCODING));
}

From source file:be.solidx.hot.test.data.jdbc.TestJsAsyncCollectionApi.java

@Test
public void testAsync() throws Exception {
    JSScriptExecutor executor = new JSScriptExecutor();
    Map<String, Object> context = new HashMap<>();
    context.put("db", db);
    context.put("adb", new JSAsyncDB(db, Executors.newCachedThreadPool(), Executors.newSingleThreadExecutor(),
            executor.getGlobalScope()));

    executor.setGlobalScopeScripts(Arrays.asList("/js/qunit-1.14.js"));
    Script<org.mozilla.javascript.Script> script = new Script<>(
            IOUtils.toByteArray(/*from   w  w  w .  ja  va2s  . c om*/
                    getClass().getResourceAsStream("/be/solidx/hot/test/data/jdbc/scripts/async-db.js")),
            "async-db.js");
    StringWriter out = new StringWriter();
    executor.execute(script, context, out);
    System.out.println(out.toString());
    Assert.assertFalse(out.toString().contains("FAIL"));
}

From source file:com.microsoft.rest.ServiceClient.java

/**
 * Initializes a new instance of the ServiceClient class.
 */
public ServiceClient() {
    this(HttpClientBuilder.create(), Executors.newCachedThreadPool());
}

From source file:com.calclab.emite.xtesting.services.HttpConnector.java

public HttpConnector() {
    sendService = Executors.newCachedThreadPool();
    receiveService = Executors.newFixedThreadPool(1);
}