Reputation: 39522
I'm attempting to find the difference in running time between multi and single core solutions in Java. So far, the single core runs fine. However, I'm getting erratic reports from the multicore solution, some reporting that it took 0 nanoseconds, or slightly more.
The multicore reads as follow: (Notice that I'm not doing anything too advanced, just trying to find the length of time it ran. CPU execution time in Java convinced me to use System.nanoTime()
instead of .currentTimeMillis()
)
long start = System.nanoTime();
Runnable r0 = new FindMagicBrute(n);
Thread t0 = new Thread(r0);
Thread t1 = new Thread(r0);
Thread t2 = new Thread(r0);
t0.start();
t1.start();
t2.start();
long end = System.nanoTime();
System.out.println("Multithreaded run ended in " + (end-start) + " nanoseconds.");
Is there a way to determine when a thread has stopped executing?
Upvotes: 0
Views: 182