-1

Is there is any mechanism in java through which we can communicate to the running thread and find from how much time it is running?

Harshal Patil
  • 6,659
  • 8
  • 41
  • 57
  • 2
    Hi!! Welcome to Stack Overflow. Please note that this is a Q&A site, where you post problematic code and errors and other users kindly point the issues in your code. Thank You – Harshal Patil Apr 08 '14 at 10:02

2 Answers2

1

to calculate time of processing, you can do like below:

long startTime = System.currentTimeMillis();
//your process
long finishTime = System.currentTimeMillis();
long duration = finishTime - startTime;//unit is milisecond
tana
  • 585
  • 1
  • 5
  • 16
  • I should run another function after the thread runnning for 3 seconds – user3509487 Apr 08 '14 at 10:11
  • So, you should to consider to use Timer to make sure the 3 seconds. http://docs.oracle.com/javase/7/docs/api/java/util/Timer.html – tana Apr 08 '14 at 10:19
0

Or, if you want to measure how much CPU time is used by an individual thread, see this answer:

CPU execution time in Java

Community
  • 1
  • 1
Solomon Slow
  • 25,130
  • 5
  • 37
  • 57