BAR
BAR

Reputation: 17061

Java Executor - Single Thread Multiple Task

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?

Upvotes: 5

Views: 4501

Answers (1)

Jerry Andrews
Jerry Andrews

Reputation: 847

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.

Upvotes: 3

Related Questions