Connecting Tech Pros Worldwide Help | Site Map

Updating time...

Needs Regular Fix
 
Join Date: Nov 2007
Location: Cebu City, Philippines
Posts: 508
#1: Apr 4 '08
I am planning to add a clock on my program....

My idea is to implement it using ExecutorService....

Im planning also to have a new Runnable...
That will update the Clock and execute it from ExecutorService....

Im not sure of my plans as of now....

Is this possible?
If it is, will the performance of my program slows down?
Because, i think that updating the clock is to have a reasonable infinite loop with a minimum delay time interval....

Can you advice me experts about this?
Any algorithm?

Waiting for your replies,
sukatoa....
JosAH's Avatar
Expert
 
Join Date: Mar 2007
Posts: 10,611
#2: Apr 4 '08

re: Updating time...


The most accurate time you have on your system is from System.currentTimeMillis() .
Call that method periodically (Thread.sleep(1000) comes to mind) and convert
those milli seconds to an hour/minutes/seconds form and display it.

Especially that sleep(1000) call makes the loop quite cheap (it passes control
to other threads).

kind regards,

Jos
Needs Regular Fix
 
Join Date: Nov 2007
Location: Cebu City, Philippines
Posts: 508
#3: Apr 4 '08

re: Updating time...


Quote:

Originally Posted by JosAH

The most accurate time you have on your system is from System.currentTimeMillis() .
Call that method periodically (Thread.sleep(1000) comes to mind) and convert
those milli seconds to an hour/minutes/seconds form and display it.

Especially that sleep(1000) call makes the loop quite cheap (it passes control
to other threads).

kind regards,

Jos

........Roger..........
Reply