I have a multithreaded application. When using Thread.start () to manually start threads, each parallel thread uses exactly 25% of the CPU (or exactly one core - this is on a quad-core processor). Therefore, if I run two threads, then the processor utilization is exactly 50%.
However, when using the ExecutorService to start threads, it seems that one ghost thread consumes CPU resources! One Thread uses 50% instead of 25%, two threads use 75%, etc.
Could this be some kind of artifact of the Windows task manager?
Excutor Service Code
ExecutorService executor = Executors.newFixedThreadPool(threadAmount); for (int i = 1; i < 50; i++) { Runnable worker = new ActualThread(i); executor.execute(worker); } executor.shutdown(); while (!executor.isTerminated()) { } System.out.println("Finished all threads");
and Thread.start () code:
ActualThread one= new ActualThread(2,3); ActualThread two= new ActualThread(3,4); ... Thread threadOne = new Thread(one); Thread threadTtwo = new Thread(two); ... threadOne.start(); threadTwo.start(); ...
java performance multithreading
Oliver
source share