How to get to FutureTask execution state?

前端 未结 4 1014
情话喂你
情话喂你 2021-01-05 20:50

I have a singleThreadExecutor in order to execute the tasks I submit to it in serial order i.e. one task after another, no parallel execution.

I have runnable which

4条回答
  •  执笔经年
    2021-01-05 21:38

    You could wrap anything you submit to this service in a Runnable that records when its run method is entered.

    public class RecordingRunnable implements Runnable {
        private final Runnable actualTask;
        private volatile boolean isRunning = false;
        //constructor, etc
    
        public void run() {
            isRunning = true;
            actualTask.run();
            isRunning = false;
        }
    
        public boolean isRunning() {
           return isRunning;
        }
    }
    

提交回复
热议问题