Hi
Here is some code. I want to be able to end this code in an elegant fashion (instead of just hitting ctrl c or the x in the console window).
Something like pressing q to quit would be nice. Is it possible to set up an interrupt that goes off when I hit Q? I don't want to have to set up infinite loops checking for keypresses etc.
Cheers
Al
import java.util.*;
import java.text.*;
public class StartManager extends
Thread { public void run()
{ // Run the start and reminder tasks programs after 30 mins
Calendar rightnow = Calendar.getInstance();
int hrs = rightnow.get(Calendar.HOUR);
System.out.println("WF Event Manager - Running...");
while(true)
{
String checktime = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT).format(new java.util.Date());
rightnow = Calendar.getInstance();
int check = rightnow.get(Calendar.HOUR);
if(hrs != check)
{ // An hour has elapsed so start the task checks.
System.out.println("WF Event Manager - 1 Hour has elapsed - starting checks...");
hrs = check;
ReminderTask rtask = new ReminderTask();
StartTask stask = new StartTask();
rtask.start();
stask.start();
}
else
{ System.out.println("WF Event Manager -
testing time - " + checktime);
try
{ // 30 mins is 1800000 nanoseconds
this.sleep(1800000);
}
catch(InterruptedException e){}
}
}
}
}