Seconds from Thread

Hello. I am trying to make a timer of sorts that times seconds and minutes. the only problem is the thread I created isn't timing exact seconds like it should. I know that a thread is supposed to sleep for a certain amount ofmiliseconds so why won't it come out even? Making the thread sleep for 16 "miliseconds" is the closest I can get to the real thing but It's still slightly too slow. 17 is too fast. Any ideas?

publicvoid run()

{

while(true)

{

doStuff();

}

}

publicvoid doStuff()

{

try

{

thread.sleep(16);

}

catch(InterruptedException e){}

if(timingcycle == 2)

{

miliseconds++;

if(miliseconds == 60)

{

seconds++;

miliseconds = 0;

if(seconds == 60)

{

minutes++;

seconds = 0;

}

}

}

repaint();

}

[1707 byte] By [etgohomeoka] at [2007-11-26 15:39:11]
# 1
doing a thread.sleep will sleep for a minimum number of milliseconds, but it doesn't guarantee that your thread will wake up right after sleeping.You may, however, want to try setting your thread's priority to HIGH and see if you get better results
tjacobs01a at 2007-7-8 21:57:31 > top of Java-index,Java Essentials,New To Java...
# 2

One thing i have observed is that setting a thread to sleep for a particular time doesn't necessari;y make it to get to wake up after the specified time especially when you are running multiple threads because of the context switch overhead and certain other factors which i am unaware of because i didn't get the perfect results everytime.

qUesT_foR_knOwLeDgea at 2007-7-8 21:57:31 > top of Java-index,Java Essentials,New To Java...