Is there any possibility to count the working time of a processes in java?
for example in a pseudo code
for(some Object:all Objects){
startProcess1();
....
startProcessn();}
if(startProcess1 is finished){
getTimeOfProcessOne()}
Thanks
Processing time of a thread/objects in java can be determined as
ThreadMXBean bean=ManagementFactory.getThreadMXBean();
long id=Thread.currentThread().getId();
long start,end;
if(!bean.isThreadCpuTimeSupported()){System.exit(0);}
start=bean.getThreadCpuTime(id);
//Call some methods , process some objects
end=bean.getThreadCpuTime(id)-start;
Now end
will contain processing time of Thread
with ID as id
.
This time will be in NanoSeconds.