java spring 消费者中的兔子线程池
java spring rabbit thread pool in consumer
我有一个兔子消费者,里面有一个线程池。我决定有一个线程池,因为我需要等待计算完成。但正如我所注意到的,使用 TP 会导致奇怪的效果,如冻结等。所以我想问一下,在rabbit consumer里面使用TP是否正确?是否可以使用 spring 兔子工具实现相同的功能?
...
ThreadPoolExecutor pool = new ThreadPoolExecutor(cores, 50, 30L, TimeUnit.SECONDS, new ArrayBlockingQueue<>(3000));
public void onMessage(){
pool.execute(()->{
//do something
handleMessage(...);//return to some output queue
});
}
或
public void onMessage(){
//do something
handleMessage(...);//return to some output queue
}
在侦听器容器中简单地增加 concurrentConsumers
通常比移交给您自己的线程池更好。
无论哪种方式,您的代码都必须是线程安全的。
使用您当前的解决方案,您有消息丢失的风险,因为消息在侦听器退出时得到确认。
我有一个兔子消费者,里面有一个线程池。我决定有一个线程池,因为我需要等待计算完成。但正如我所注意到的,使用 TP 会导致奇怪的效果,如冻结等。所以我想问一下,在rabbit consumer里面使用TP是否正确?是否可以使用 spring 兔子工具实现相同的功能?
...
ThreadPoolExecutor pool = new ThreadPoolExecutor(cores, 50, 30L, TimeUnit.SECONDS, new ArrayBlockingQueue<>(3000));
public void onMessage(){
pool.execute(()->{
//do something
handleMessage(...);//return to some output queue
});
}
或
public void onMessage(){
//do something
handleMessage(...);//return to some output queue
}
在侦听器容器中简单地增加 concurrentConsumers
通常比移交给您自己的线程池更好。
无论哪种方式,您的代码都必须是线程安全的。
使用您当前的解决方案,您有消息丢失的风险,因为消息在侦听器退出时得到确认。