pkrish80
asked on
Issue using two instances of Executor service one after the other?
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.newCachedThreadP ool();
TestRunner runner = new Runner(object obj);
//some code
}
finally{
service.shutdown();
service.awaittermination(1 ,TIMEUNIT. HOURS)
}
}
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.newCachedThreadP
TestRunner runner = new Runner(object obj);
//some code
}
finally{
service.shutdown();
service.awaittermination(1
}
}
They shouldn't interfere with each other, but if your intention is simply to create two threads, why not just use ONE ExecutorService?
ASKER
I need to create two services with multiple threads. Both the set of the threads will be processing different datasets. Will they run sequentially per code above?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.