does Executors.newSingleThreadExecutor() always excute tasks in order they were submitted?

巧了我就是萌 提交于 2020-12-05 07:01:31

问题


The Javadoc says that the tasks will be executed sequentially. But does sequentially here mean that the sequence will be the order that the tasks are submitted? Or does it mean that only one task will be done at a time, but may not do them in the order they were submitted?


回答1:


The javadoc says:

Creates an Executor that uses a single worker thread operating off an unbounded queue

A queue respects the insertion order. So yes, tasks will be executed in the order they were submitted.



来源:https://stackoverflow.com/questions/31765485/does-executors-newsinglethreadexecutor-always-excute-tasks-in-order-they-were

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!