corePoolSize :
ScheduleFuture<>,連Runnable排程函式都有,但我們都知道Runnable不會回傳,那為何需要Future?
.cancel 來 取消任務的排程(當然這建立在任務還沒被執行啦w,若已經開始了,則會嘗試使用interrupt去觸發try-catch)。<> 也分為 <?>(for Runabble,無回傳) 及 <V>(for Callable)。schedule.scheduleWithFixedDelay(
() -> {
long seconds = System.currentTimeMillis() / 1000;
System.out.println("Excuted at : " + seconds + " seconds");
try{
Thread.sleep(3000);
}catch (InterruptedException e){
System.out.print(e.getMessage());
}
},
3, 3, TimeUnit.SECONDS
); // 意即每次執行任務間隔「至少」6秒
本篇文章出自《每天學Java直到今年結束》Day217,大家可以到我的網站上查看~