Executors.newSingleThreadExecutor() 是否总是按照提交的顺序执行任务? [英] does Executors.newSingleThreadExecutor() always excute tasks in order they were submitted?

查看:186
本文介绍了Executors.newSingleThreadExecutor() 是否总是按照提交的顺序执行任务?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Javadoc 表示任务将按顺序执行.但是这里的顺序是否意味着顺序就是任务提交的顺序?还是说一次只能做一个任务,但不一定按照提交的顺序去做?

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?

推荐答案

javadoc 说:

创建一个 Executor,它使用单个工作线程在无界队列中运行

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.

这篇关于Executors.newSingleThreadExecutor() 是否总是按照提交的顺序执行任务?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆