If an execution isĭelayed for any reason (such as garbage collection or other backgroundĪctivity), two or more executions will occur in rapid succession to Scheduled execution time of the initial execution. In fixed-rate execution, each execution is scheduled relative to the
Schedules the specified task for repeated fixed-rate execution,Īt approximately regular intervals, separated by the specified period.
Is delayed for any reason (such as garbage collection or otherīackground activity), subsequent executions will be delayed as well. The actual execution time of the previous execution. In fixed-delay execution, each execution is scheduled relative to Subsequent executions take placeĪt approximately regular intervals separated by the specified period. Schedules the specified task for repeated fixed-delay execution,īeginning after the specified delay. Implementation note: All constructors start a timer thread. It uses a binary heap to represent its task queue, so the cost to scheduleĪ task is O(log n), where n is the number of concurrently scheduled tasks. Scheduled tasks (thousands should present no problem). Implementation note: This class scales to large numbers of concurrently Configuring ScheduledThreadPoolExecutor with one thread makes it equivalent to Time units, and doesn't require subclassing TimerTask (just
Versatile replacement for the Timer/ TimerTaskĬombination, as it allows multiple service threads, accepts various One of the concurrency utilities therein is the ScheduledThreadPoolExecutor which is a thread pool for repeatedlyĮxecuting tasks at a given rate or delay. Tasks using the Object.wait(long) method. This class does not offer real-time guarantees: it schedules Timer object without the need for external synchronization. This class is thread-safe: multiple threads can share a single IllegalStateException, as if the timer's cancel If the timer's task execution thread terminates unexpectedly, forĮxample, because its stop method is invoked, any furtherĪttempt to schedule a task on the timer will result in an Wants to terminate a timer's task execution thread rapidly, the caller So it is capable of keeping an application from terminating. Byĭefault, the task execution thread does not run as a daemon thread, However, this can take arbitrarily long to occur. Turn, delay the execution of subsequent tasks, which may "bunch up" andĮxecute in rapid succession when (and if) the offending task finallyĪfter the last live reference to a Timer object goes awayĪnd all outstanding tasks have completed execution, the timer's taskĮxecution thread terminates gracefully (and becomes subject to garbageĬollection). To complete, it "hogs" the timer's task execution thread. Thread that is used to execute all of the timer's tasks, sequentially. Tasks may be scheduled for one-time execution, or forĬorresponding to each Timer object is a single background A facility for threads to schedule tasks for future execution in aīackground thread.