需要注意的是線程池必須使用shutdown來顯式關閉
許多長時間運行的應用有時候需要定時運行任務完成一些諸如統計
packageconcurrent;
importstaticjava
importjava
importjava
importjava
importjava
publicclassTestScheduledThread{
publicstaticvoidmain(String[]args){
finalScheduledExecutorServicescheduler=Executors
finalRunnablebeeper=newRunnable(){
intcount=
publicvoidrun(){
System
}
};
//
finalScheduledFuture<?>beeperHandle=scheduler
beeper
//
finalScheduledFuture<?>beeperHandle
//
scheduler
publicvoidrun(){
beeperHandle
beeperHandle
scheduler
}
}
}
}
為了退出進程
[
From:http://tw.wingwit.com/Article/program/Java/gj/201311/27714.html