I want to wait for a specific time to execute a function but I get the
Error: Thread[2,tid=3699,WaitingInMainSignalCatcherLoop,Thread*=0xa9f2c500,peer=0x36c090a0,"Signal Catcher"]: reacting to signal 3
during the "sleepUntil" function:
try {
TimeInMillis = getTimeInMillis();
currentTimeMillis = System.currentTimeMillis();
sleepUntil(TimeInMillis);
} catch (InterruptedException e) {
e.printStackTrace();
}
Function to calculate time in milliseconds:
public long getTimeInMillis(){
long TimeInMillis = 0;
Date date = new Date();
currentDate = dateformatter.format(date);
updateTime = currentDate + " " + updateTime;
try {
parseTime = formatter.parse(updateTime);
TimeInMillis = parseTime.getTime();
} catch (ParseException e) {
e.printStackTrace();
}
System.out.println(TimeInMillis);
System.out.println(System.currentTimeMillis());
return TimeInMillis;
}
Function to wait:
public static void sleepUntil(long date) throws InterruptedException {
//Thread.sleep(Math.max(date - System.currentTimeMillis(),0));
TimeUnit.MILLISECONDS.sleep(Math.max(date-System.currentTimeMillis(),0));