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:com.ljn.msg.delimiter.Server.java

public void run() {
    // Configure the server.
    ServerBootstrap bootstrap = new ServerBootstrap(new NioServerSocketChannelFactory(
            Executors.newCachedThreadPool(), Executors.newCachedThreadPool()));

    // Set up the pipeline factory.
    bootstrap.setPipelineFactory(new ChannelPipelineFactory() {
        public ChannelPipeline getPipeline() throws Exception {
            ChannelPipeline pipeline = Channels.pipeline();

            ChannelBuffer delimiter = ChannelBuffers
                    .copiedBuffer(Constant.SEPARATOR.getBytes(CharsetUtil.UTF_8));
            pipeline.addLast("frameDecoder", new DelimiterBasedFrameDecoder(8192, delimiter));
            pipeline.addLast("stringDecoder", new StringDecoder(Charsets.UTF_8));
            pipeline.addLast("serverHandler", new ServerHandler());

            return pipeline;
        }//from w  w w.  j ava 2 s  .com
    });

    // Bind and start to accept incoming connections.
    bootstrap.bind(new InetSocketAddress(port));
}

From source file:com.azaptree.services.http.HttpServiceConfig.java

/**
 * /*from   w ww  . jav a  2  s .  c  om*/
 * @param name
 *            REQUIRED
 * @param httpRequestHandler
 *            REQUIRED
 */
public HttpServiceConfig(final String name, final Handler httpRequestHandler) {
    Assert.hasText(name, "name is required");
    Assert.notNull(httpRequestHandler, "httpRequestHandler is required");
    this.name = name;
    this.httpRequestHandler = httpRequestHandler;
    requestExcecutorService = Executors.newCachedThreadPool();
    port = 8080;
}

From source file:org.msjs.config.MsjsModule.java

/**
 * Constructs a guice module for msjs./*from  w ww.java2  s  .  c o  m*/
 *
 * @param config The configuration for the application.
 */
public MsjsModule(MsjsConfiguration config) {
    this.config = config;
    executorService = Executors.newCachedThreadPool();
    connectionManager = getConnectionManager();
    timer = new Timer();
}

From source file:com.microsoft.azure.servicebus.samples.topicsgettingstarted.TopicsGettingStarted.java

public void run(String connectionString) throws Exception {

    TopicClient sendClient;//from   w  w w.  j a v a  2 s . c  o m
    SubscriptionClient subscription1Client;
    SubscriptionClient subscription2Client;
    SubscriptionClient subscription3Client;

    // Create a QueueClient instance using the connection string builder
    // We set the receive mode to "PeekLock", meaning the message is delivered
    // under a lock and must be acknowledged ("completed") to be removed from the queue
    subscription1Client = new SubscriptionClient(
            new ConnectionStringBuilder(connectionString, "BasicTopic/subscriptions/Subscription1"),
            ReceiveMode.PEEKLOCK);
    subscription2Client = new SubscriptionClient(
            new ConnectionStringBuilder(connectionString, "BasicTopic/subscriptions/Subscription2"),
            ReceiveMode.PEEKLOCK);
    subscription3Client = new SubscriptionClient(
            new ConnectionStringBuilder(connectionString, "BasicTopic/subscriptions/Subscription3"),
            ReceiveMode.PEEKLOCK);

    ExecutorService executorService = Executors.newCachedThreadPool();
    registerMessageHandlerOnClient(subscription1Client, executorService);
    registerMessageHandlerOnClient(subscription2Client, executorService);
    registerMessageHandlerOnClient(subscription3Client, executorService);

    sendClient = new TopicClient(new ConnectionStringBuilder(connectionString, "BasicTopic"));
    sendMessagesAsync(sendClient).thenRunAsync(() -> sendClient.closeAsync());

    // wait for ENTER or 10 seconds elapsing
    waitForEnter(10);

    CompletableFuture.allOf(subscription1Client.closeAsync(), subscription2Client.closeAsync(),
            subscription3Client.closeAsync()).join();

    executorService.shutdown();
}

From source file:com.ejisto.modules.executor.TaskManager.java

public TaskManager() {
    this.registry = new ConcurrentHashMap<>();
    this.executorService = Executors.newCachedThreadPool();
    this.scheduler = Executors.newScheduledThreadPool(5);
    this.scheduler.scheduleAtFixedRate(this::refreshTasksList, 500L, 500L, MILLISECONDS);
}

From source file:com.stimulus.archiva.incoming.IAPService.java

public void startup() {
    MailboxConnection connection;/*from ww w.  j  a  va2 s .c  om*/
    Config config = Config.getConfig();
    connection = config.getMailboxConnections().getConnection();
    executor = Executors.newCachedThreadPool();
    iapworker = new IAPRunnable("mailbox worker", null, connection,
            config.getMailboxConnections().getPollingIntervalSecs(),
            Config.getConfig().getFetchMessageCallback());
    logger.debug("startup {name='" + iapworker.getName() + "'}");
    if (connection.getEnabled()) {
        executor.execute(iapworker);
    }
    serviceDelegate.startup();
}

From source file:infrascructure.data.readers.AdvancedResourcesRepository.java

@Override
public void readAll() throws IOException {
    int threads = config.getPropertyInt(Config.CRAWL_THREADS, 1);
    int i = rawdocs.size();
    index = new AtomicInteger(i);

    ExecutorService pool = Executors.newCachedThreadPool();
    for (int t = 0; t < threads; t++) {
        pool.submit(this);
    }/* w ww  .  j a v  a 2 s  .  c om*/
}

From source file:com.github.jarlakxen.embedphantomjs.executor.PhantomJSFileExecutor.java

public PhantomJSFileExecutor(PhantomJSReference phantomReference, ExecutionTimeout executionTimeout) {
    this(phantomReference, Executors.newCachedThreadPool(), executionTimeout);
}

From source file:com.hunch.ImageManager.java

private static void startExecutor() {
    // if we already have an executor, theres no need for another one.
    if (executor != null)
        return;//from  www .j a v a2s  . c  o  m

    if (Const.IMG_FETCH_THREADS > 1)
        executor = Executors.newFixedThreadPool(Const.IMG_FETCH_THREADS);
    else if (Const.IMG_FETCH_THREADS == 1)
        executor = Executors.newSingleThreadExecutor();
    else
        executor = Executors.newCachedThreadPool();
}

From source file:org.springframework.social.twitter.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.addMixInAnnotations(Tweet.class, TweetMixin.class);
    objectMapper.addMixInAnnotations(StreamDeleteEvent.class, StreamDeleteEventMixin.class);
    objectMapper.addMixInAnnotations(StreamWarningEvent.class, StreamWarningEventMixin.class);
    objectMapper.addMixInAnnotations(StreamEvent.class, StreamEventMixin.class);
    objectMapper.addMixInAnnotations(DirectMessage.class, DirectMessageMixin.class);
    objectMapper.addMixInAnnotations(TwitterProfile.class, TwitterProfileMixin.class);
    active = new AtomicBoolean(true);
}