簡體   English   中英

ExecutorService在每個任務之前和之后調用一個方法

[英]ExecutorService invoke a method before and after each task

如果我有:

ScheduledExecutorService scheduledExecutorService = Executors.newScheduledThreadPool(10);

運行10個線程:

scheduledExecutorService.scheduleAtFixedRate(thread, initialDelay, delay, TimeUnit.MILLISECONDS);

如何在執行每個任務之前調用方法foo() ,並在完成每個任務之后調用bar()

您可以嘗試使用AspectJ oder AOP破解某些內容。 這會中斷應用程序流程並使用自定義方法執行一個方面。

或者,您在線程內調用foo()bar()

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM