Search in sources :

Example 1 with StandardThreadExecutor

use of com.jeesuite.common.async.StandardThreadExecutor in project jeesuite-libs by vakinge.

the class MNSConsumer method start.

private void start() {
    CloudQueue queue = MNSClientInstance.createQueueIfAbsent(queueName);
    initTopicHanlders();
    fetchExecutor = new StandardThreadExecutor(1, 1, 0, TimeUnit.SECONDS, 1, new StandardThreadFactory("mns-Fetch-Executor"));
    int maxThread = ResourceUtils.getInt("aliyun.mns.consumer.processThreads", 50);
    semaphore = new Semaphore(maxThread);
    defaultProcessExecutor = new StandardThreadExecutor(1, maxThread, 60, TimeUnit.SECONDS, 1, new StandardThreadFactory("mns-defaultProcess-Executor"));
    fetchExecutor.submit(new Worker(queue));
    logger.info("start work for queue Ok -> queue:{}", queue.getQueueURL());
}
Also used : StandardThreadExecutor(com.jeesuite.common.async.StandardThreadExecutor) StandardThreadFactory(com.jeesuite.common.async.StandardThreadExecutor.StandardThreadFactory) Semaphore(java.util.concurrent.Semaphore) CloudQueue(com.aliyun.mns.client.CloudQueue)

Example 2 with StandardThreadExecutor

use of com.jeesuite.common.async.StandardThreadExecutor in project jeesuite-libs by vakinge.

the class AbstractConsumer method startWorker.

protected void startWorker() {
    // 异步处理拉取线程默认1
    int fetchCoreThreads = 1;
    int fetchMaxThreads = fetchCoreThreads;
    // 异步处理
    if (MQContext.isAsyncConsumeEnabled()) {
        int maxThread = MQContext.getMaxProcessThreads();
        semaphore = new Semaphore(maxThread);
        this.asyncProcessExecutor = new StandardThreadExecutor(1, maxThread, 60, TimeUnit.SECONDS, maxThread, new StandardThreadFactory("messageAsyncProcessor"));
        // 
        fetchMaxThreads = maxThread;
        logger.info("init asyncProcessExecutor finish -> maxThread:{}", maxThread);
    }
    // 
    this.fetchExecutor = new StandardThreadExecutor(fetchCoreThreads, fetchMaxThreads, 0, TimeUnit.SECONDS, fetchMaxThreads * 10, new StandardThreadFactory("messageFetcher"));
    fetchExecutor.execute(new Worker());
    logger.info("init fetchExecutor finish -> fetchMaxThreads:{}", fetchMaxThreads);
}
Also used : StandardThreadExecutor(com.jeesuite.common.async.StandardThreadExecutor) StandardThreadFactory(com.jeesuite.common.async.StandardThreadExecutor.StandardThreadFactory) Semaphore(java.util.concurrent.Semaphore)

Aggregations

StandardThreadExecutor (com.jeesuite.common.async.StandardThreadExecutor)2 StandardThreadFactory (com.jeesuite.common.async.StandardThreadExecutor.StandardThreadFactory)2 Semaphore (java.util.concurrent.Semaphore)2 CloudQueue (com.aliyun.mns.client.CloudQueue)1