Win a copy of Java Concurrency Live Lessons this week in the Threads forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

How to get Thread execution time ?  RSS feed

 
Akshay Rathore
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator



I want to find out the time Mycode portion has taken to execute. I used the above function to find this out. But I am not sure whether the duration I get is the time taken by this portion alone or does it include the total time taken from start to finish which may include time taken by other processes and background jobs running in my computer. In other words I want the time taken by Mycode portion to execute in the absence of all other system processes. Is this the correct function to use or is there any other function to achieve that?
 
Stephan van Hulst
Saloon Keeper
Posts: 7006
110
  • Likes 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm not 100% sure, but I think that's a correct way to make a best effort time measurement for a specific thread, excluding the time that other treads take in the mean time. However, it includes the time that the thread has spent in system space (calls to the kernel). If you only want the time it has spent inside your application, you should use getThreadUserTime().

Note that ThreadMXBean has getCurrentThreadCpuTime() and getCurrentThreadUserTime(), which are more convenient to call than what you're doing.
 
Akshay Rathore
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you so much for the help.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!