Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 834
Daniel Avatar asked Aug 01 '15 19:08

Daniel


1 Answers

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.

like image 70
JB Nizet Avatar answered Sep 29 '22 18:09

JB Nizet