简体   繁体   中英

How to capture elapsed time of a running java process to raise intermediate alerts

I have a java process which could either complete sooner or take longer time based on the volume of data its processing. However I need a way to capture the elapsed time after certain time continuously and need to log an alert message concurrently without interrupting the main process. I have explored Future option with ExecutorService but it would terminate the process after the set timeout and raises Timeout exception. Please suggest if you have any solution to achieve this requirement.

just some hints:

  • you need to have 2 separate threads: one for main logic and one for checking the progress
  • the thread that checks the progress should be able to know if the main thread has finished or not (the simplest solution volatile boolean flag)
  • the thread that checks the progress can be invoked by timer with some period

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM