This code works just fine as far as it goes. I take a time like 3:15PM from an inputText. I break that down into hours and minutes. I create a GregorianCalendar now and take the milliseconds. I then create another GregorianCalendar with the 3:15 milliseconds. I want the timer to stop 1 minute before 3:15 so I subtract another minute from the difference such as later - now - 60000.
This code works as far as it goes, but I can see no way to trigger the JSF to executed a warning. Of course when I click the commandButton to kick this off, it runs through this code, starting the timer and returning "hhraDisplay". That's what I need help with. When the timer finishes, I see task complete on the console.
I recieved a notification from Stackoverflow that this question had been previously answered and was therefore closed. The problem is the link to the supposed answer has ABSOLUTELY NOTHING to do with the question I posed.
public String doReminder() {
String pt = getRacePostTime();
pt = pt.substring(0, pt.indexOf("M") -1);
String [] ptArray = pt.split(":");
int hrs, min;
hrs = Integer.valueOf(ptArray[0]);
min = Integer.valueOf(ptArray[1]);
Calendar cal = new GregorianCalendar();
long now = cal.getTimeInMillis();
cal.set(Calendar.HOUR, hrs);
cal.set(Calendar.MINUTE, min);
cal.set(Calendar.SECOND, 1);
long later = cal.getTimeInMillis();
ScheduledExecutorService executor = Executors.newScheduledThreadPool(1);
Runnable task = () -> {
// Your custom logic here
System.out.println("task complete");
executor.shutdown();
};
long initialDelay = later - now - 60000; // Initial delay (in milliseconds)
long period = 1; // Repeat every 1 second
executor.scheduleAtFixedRate(task, initialDelay, period, TimeUnit.MILLISECONDS);
return "hhraDisplay";
}