Is there an out-of-the-box thread pool with multiple queues (that ensure serial processing of each queue)?

后端 未结 7 716
星月不相逢
星月不相逢 2020-12-16 11:22

Among all my tasks, I have some that must be processed serially (they can never run concurrently and they must be processed in order).

I achieved that creating a sep

7条回答
  •  没有蜡笔的小新
    2020-12-16 12:09

    A single thread executor will do

    ExecutorService  executorService = Executors.newSingleThreadExecutor();
    

    Which internally uses a ThreadPoolExecutor with a LinkedBlockingQueue

    new ThreadPoolExecutor(1, 1,0L, TimeUnit.MILLISECONDS,
                                    new LinkedBlockingQueue()))
    

    So you can use this for your sequential stuff and probably use a multi-threaded executor service for concurrent tasks

提交回复
热议问题