`

Timer的混乱行为

 
阅读更多

import java.util.Timer;
import java.util.TimerTask;

public class OutOfTime
{
    public static void main(String[] args) throws InterruptedException
    {
        Timer timer = new Timer();
        timer.schedule(new ThrowTask(), 1);
        Thread.sleep(1000);
        timer.schedule(new ThrowTask(), 1);
        Thread.sleep(5000);
    }

    static class ThrowTask extends TimerTask
    {
        public void run()
        {
            throw new RuntimeException();
        }
    }
}

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics