`

Java 定时器 5秒钟后自动退出

阅读更多
一个简易的Java定时器方法, 5秒钟后退出。

private void autoExit() {
		Timer timer = new Timer();
		timer.schedule(new TimerTask() {
			int MAX_COUNTER = 5;
			int counter = 0;

			@Override
			public void run() {
				if (MAX_COUNTER == counter) {
					if (!isExitCB.isSelected()) {
						System.exit(0);
					} else {
						this.cancel();
					}
				}
				willExitLabel.setText("System will exit within "
						+ (MAX_COUNTER - counter) + " seconds");
				counter++;
			}
		}, 0, 1000);
	}
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics