Thread reacting to signal 3

问题: 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,"Si...

问题:

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));

回答1:

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

  • 发表于 2018-07-11 16:54
  • 阅读 ( 1035 )
  • 分类:sof

条评论

请先 登录 后评论
不写代码的码农
小编

篇文章

作家榜 »

  1. 小编 文章
返回顶部
部分文章转自于网络,若有侵权请联系我们删除