public class ParallelTimer extends Object
Essentially this is just a class that tracks the number of threads that have
started the timer and the time at which the timer was last started when there
were no active threads using synchronized
to ensure that only one
thread can access a method at any one time.
Then when the timer is stopped and there are no active threads the total time elapsed can be incremented by the difference between the last start time and the current time. It may be the case that multiple distinct threads have run and started and stopped the timer. But provided active threads is greater than zero at least one thread is performing the operation we wish to time so we are always counting actual time and not counting time multiply as we would be doing if we just summed the individual runtimes of the threads.
Constructor and Description |
---|
ParallelTimer() |
Modifier and Type | Method and Description |
---|---|
long |
getActiveThreads()
Gets the number of active threads currently consuming runtime in parallel
|
long |
getActualRuntime()
Gets the actual runtime consumed
|
void |
start()
Starts timing
|
void |
stop()
Stops timing
|
public void start()
public void stop()
public long getActualRuntime()
public long getActiveThreads()
Copyright © 2015. All rights reserved.