We help IT Professionals succeed at work.

threads to get the elapsed time

cutie_smily
cutie_smily asked
on
Medium Priority
225 Views
Last Modified: 2010-03-31

Can anyone write a piece of code where thread sleeps every 5 minutes. calculate elapsed time (each time get the system time and compare with the last value )(hours, minutes,seconds)
Comment
Watch Question

Java Developer
CERTIFIED EXPERT
Top Expert 2010
Commented:
elapsed time of what?

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts

Author

Commented:


get system time every 5 minutes and calculate the difference in time from the last time you got the system date
Mick BarryJava Developer
CERTIFIED EXPERT
Top Expert 2010

Commented:
why wouldn't it be 5 minutes :)

long a = System.currentTimeInMillis();
Thread.sleep(5*60*1000);
long b = System.currentTimeInMillis();

Author

Commented:


for instance now the system time is 8:55:40

after 5 minutes

system time will be 9:00:40

time diffrence= 5 minutes.

a program to calculate time difference..
Commented:
long a = System.currentTimeInMillis();
Thread.sleep(5*60*1000);
long b = System.currentTimeInMillis();

b - a = the elapsed milliseconds.  You can calculate from there.
Mick BarryJava Developer
CERTIFIED EXPERT
Top Expert 2010

Commented:
> use whjat i posted above
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.