aspose file tools
The moose likes Threads and Synchronization and the fly likes ExecutorService with 1 thread Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Threads and Synchronization
Reply Bookmark "ExecutorService with 1 thread" Watch "ExecutorService with 1 thread" New topic
Author

ExecutorService with 1 thread

Jim Bob
Greenhorn

Joined: Apr 06, 2007
Posts: 2
Hi There,

Can someone answer me this question: If I create an ExecutorService like so:

ExecutorService myService = Executors.newFixedThreadPool(1);

and then call(pseudocode):

myService.submit(sometask1);
myService.submit(sometask2);

Is it guaranteed that seeing as the ExecutorService only has one thread (see constructor above), is it guaranteed that sometask2 will only execute after sometask1 has finished?

In other words, with a pool size of 1, sometask1 and sometask2 will never execute concurrently in this situation??

thanks a lot.
Jim Bob
Greenhorn

Joined: Apr 06, 2007
Posts: 2
No probs....done!

- Jim.
Scott Selikoff
Saloon Keeper

Joined: Oct 23, 2005
Posts: 3652

"Jim Bob"

Please re-read the section on 'obviously fictitious names' and change your name appropriately.


My Blog: Down Home Country Coding with Scott Selikoff
Stan James
(instanceof Sidekick)
Ranch Hand

Joined: Jan 29, 2003
Posts: 8791
The Executor interface JavaDoc includes a sample Executor that runs one task at a time, if that's your objective.


A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: ExecutorService with 1 thread
 
Similar Threads
How to stop a Thread
Process completes and abruptly stops its threads?
Why the Runnable cant be resolved
doubt i thread mock
How can I serialize thread handling with Java 5's java.util.concurrent package?