Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Thread reacting to signal 3

Tags:

java

android

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));
like image 632
user12346352 Avatar asked Mar 06 '23 20:03

user12346352


1 Answers

You should not use a thread on the main thread(UI thread). You are getting this error because service runs on main thread and you are trying to pause main thread using sleep, try implementing your logic using this and you can use SystemClock.sleep(millis) for wait

like image 55
MadLeo Avatar answered Mar 16 '23 11:03

MadLeo