Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java Executor - Single Thread Multiple Task

Tags:

java

executor

Can an Executor run multiple tasks on a single thread?

Obviously the task execution cannot happen simultaneously with only one physical core to run on, but is there a way to wait or yield so the other submitted tasks can run?

If there is not a wait then how else can one determine, generally, when the other task will run?

like image 727
BAR Avatar asked Oct 21 '22 02:10

BAR


1 Answers

Yes.

Not with the current implementations.

No.

;)

Consider the documentation on SingleThreadExecutor (http://docs.oracle.com/javase/1.5.0/docs/api/java/util/concurrent/Executors.html#newSingleThreadExecutor()), and Wait between tasks with SingleThreadExecutor on StackOverflow.

You could implement your own thread-sharing lock between threads, and run them on a multi-thread executor... but if you want someone else's implementation to do that, well, as far as I know, you're out of luck.

like image 76
Jerry Andrews Avatar answered Oct 24 '22 12:10

Jerry Andrews