Link to home
Start Free TrialLog in
Avatar of pkrish80
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.newCachedThreadPool();
TestRunner runner = new Runner(object obj);
//some code
}
finally{

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

}
}
Avatar of CEHJ
CEHJ
Flag of United Kingdom of Great Britain and Northern Ireland image

They shouldn't interfere with each other, but if your intention is simply to create two threads, why not just use ONE ExecutorService?
Avatar of pkrish80
pkrish80

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
Avatar of gordon_vt02
gordon_vt02

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial