This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Threads and Synchronization and the fly likes Any problem with using two instances of Executor service one after the other? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Threads and Synchronization
Bookmark "Any problem with using two instances of Executor service one after the other?" Watch "Any problem with using two instances of Executor service one after the other?" New topic
Author

Any problem with using two instances of Executor service one after the other?

Prasan krishnan
Greenhorn

Joined: Mar 02, 2009
Posts: 1
In my code, I have two instances of of Executor Service with cached thread pools.

For example,

I have my service calling the runner object which implements runnable. I call runProcess method twice in a row. My question is if this is if one service will interfere with the other service. I need the threads in each service to finish one after the other. Please let me know.

void runProcess(){

try{
ExecutorService service = Executors.newCachedThreadPool();
TestRunner runner = new Runner(object obj);
//some code
}
finally{

service.shutdown();
service.awaittermination(1,TIMEUNIT.HOURS)

}
}


Ranganathan Kaliyur Mannar
Bartender

Joined: Oct 16, 2003
Posts: 1076
    
  10

The call to Executors.newCachedThreadPool(); creates a new ExectuorService each time. So, they won't interfere with each other.
However, there is no gaurantee on which service will finish first.


Ranga.
SCJP 1.4, OCMJEA/SCEA 5.0.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Any problem with using two instances of Executor service one after the other?
 
Similar Threads
Question on Thread/sychronized
Thread and variable value question?
Web Service question
Runnable object use
ExecutorService invokeAll - blocking?