Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The <code>ScheduledThreadPoolExecutor</code> allows you to execute your task right away or schedule it to be executed later (you can set periodical executions also). </p> <p>So, if you will use this class to stop your task execution keep in mind this:</p> <ol> <li>There is no way to guarantee that one thread will stop his execution. Check the Thread.interrupt() documentation.</li> <li>The method <code>ScheduledThreadPoolExecutor.shutdown()</code> will set as canceled your task, and it will not try to interrupt your threads. With this method you actually avoid the execution of newer tasks, and the execution of scheduled but not started tasks.</li> <li>The method <code>ScheduledThreadPoolExecutor.shutdownNow()</code> will interrupt the threads, but as I said in the first point of this list ...</li> </ol> <p><strong>When you want to stop the scheduler you must do something like this:</strong></p> <pre><code> //Cancel scheduled but not started task, and avoid new ones myScheduler.shutdown(); //Wait for the running tasks myScheduler.awaitTermination(30, TimeUnit.SECONDS); //Interrupt the threads and shutdown the scheduler myScheduler.shutdownNow(); </code></pre> <p><strong>But what if you need to stop only one task?</strong></p> <p>The method <code>ScheduledThreadPoolExecutor.schedule(...)</code> returns a <code>ScheduleFuture</code> that is a representation of your already scheduled task. So, you can call the <code>ScheduleFuture.cancel(boolean mayInterruptIfRunning)</code> method to cancel your task and try to interrupt it if you need to.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload