I'm trying to change the execution of a report and have it done in concurrency. In a 'serail mode' the execution test takes 30 seconds and when using a concurrent mode I get 27 seconds (consider that few steps must be taken in serial I'm ok with the result).
The thing that I still don't get is this line:
ExecutorService executor = Executors.newFixedThreadPool(4);
My computer is armed with 2x2.6 Ghz Quad Core and I would expect that the execution time will decrease if the newFixedThreadPool is high (16). In reality, the more I increase the newFixedThreadPool the slower the execution. This begs the question: What am I doing wrong or what am I failing to understand?!?!
I'm embedding 2 results screenshots from my execution.
A. newSingleThreadExecuter - runs in 23 sec
B. newFixedThreadPool(4) - runs in 43 sec.
Each time I submit a 'Worker' I get system.out the currentTimeMillis and the "fatched tkt" result is milliseconds that it takes to get the data from the db. (in strategy A - it takes ~3ms and in B up to 7ms).
Stopper stopper = new Stopper();
for (Long iNum : multimap.asMap().keySet())
{
List<Long> tickets = (List<Long>) multimap.get(iNum);
for (Long ticketNumber : tickets)
{
pojoPks = getPkData(iNum);
Callable<PojoTicket> worker = new MaxCommThread(ticketNumber, pojoPks);
Future<PojoTicket> submit = executor.submit(worker);
futures.add(submit);
}
}
System.out.println("futurues: " +futures.size());
for (Future<PojoTicket> future : futures)
{
try
{
PojoTicket pojoTicket = future.get();
//do the rest here
} catch (InterruptedException e)
{
System.out.println("---------------------->InterruptedException");
} catch (ExecutionException e)
{
System.out.println("---------------------->ExecutionException");
}
}
executor.shutdown();
stopper.stop();