读书人

Timer的纷乱行为

发布时间: 2012-09-25 09:55:58 作者: rapoo

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();
??????? }
??? }
}

读书人网 >编程

热点推荐