Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Prasan krishnan
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1101
10
Java Netbeans IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic