Thread testing for time
- by DanielFH
Hi there :)
I'm making a thread for my application that's going to do an exit operation at a given time (only hours and minutes, day/month doesn't matter). Is this the right way to do it, and also the right way to test for time? I'm testing for a 24 hour clock by the way, not AM / PM.
I'm then in another class going to call this something like
new Thread(new ExitThread()).start();
public class ExitThread implements Runnable {
@Override
public void run() {
Date date = new Date(System.currentTimeMillis());
String time = new SimpleDateFormat("HHmmss").format(date);
int currentTime = Integer.parseInt(time);
int exitTime = 233000;
while(true) {
try {
Thread.sleep(10000);
} catch (InterruptedException e) {
e.printStackTrace();
}
if(currentTime >= exitTime ) {
// do exit operation here
}
}
}
Thanks.
//D