我創建了一個食品訂購系統,當按下按鈕時,它將調用一個方法,然後查詢數據庫以找出當前數量,然後查詢另一個表以找出數量每道菜需要,然後用新數量更新數據庫。這需要一兩秒鐘的時間,所以我想在用戶每次訂購一個項目時在新的線程上運行它,以便在每次按下按鈕後都不會掛起。我試圖用executorService,但我仍然得到一個InvocationTargetException錯誤。 下面是代碼: public E
從控制器類溝通,我打電話這個助手啓動一個進程並返回到該進程啓動的UI 助手類: public class Helper {
public String startService() { //Before starting the service I save the status of the service as Started in the DB
ExecutorService
對Java,但我想不通爲什麼這個程序沒有結束: import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
class Main {
public static void main(String[] args) {
ScheduledExecut
enter image description here即使在調用執行程序中斷shutdownNow方法後,線程也不會停止。 線程調用功能正在while循環中運行,它正在檢查中斷標誌。 我試過在一段時間後向正在運行的線程發送中斷標誌,但它仍然在執行。我想強制停止線程。 任何人都可以說出這種行爲。 附加樣本Java代碼: public class TestExecutor {
static v