Java 定时器 5秒钟后自动退出
一个简易的Java定时器方法, 5秒钟后退出。
private void autoExit() {Timer timer = new Timer();timer.schedule(new TimerTask() {int MAX_COUNTER = 5;int counter = 0;@Overridepublic 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);}