
- Java.util Package Classes
- Java.util - Home
- Java.util - ArrayDeque
- Java.util - ArrayList
- Java.util - Arrays
- Java.util - BitSet
- Java.util - Calendar
- Java.util - Collections
- Java.util - Currency
- Java.util - Date
- Java.util - Dictionary
- Java.util - EnumMap
- Java.util - EnumSet
- Java.util - Formatter
- Java.util - GregorianCalendar
- Java.util - HashMap
- Java.util - HashSet
- Java.util - Hashtable
- Java.util - IdentityHashMap
- Java.util - LinkedHashMap
- Java.util - LinkedHashSet
- Java.util - LinkedList
- Java.util - ListResourceBundle
- Java.util - Locale
- Java.util - Observable
- Java.util - PriorityQueue
- Java.util - Properties
- Java.util - PropertyPermission
- Java.util - PropertyResourceBundle
- Java.util - Random
- Java.util - ResourceBundle
- Java.util - ResourceBundle.Control
- Java.util - Scanner
- Java.util - ServiceLoader
- Java.util - SimpleTimeZone
- Java.util - Stack
- Java.util - StringTokenizer
- Java.util - Timer
- Java.util - TimerTask
- Java.util - TimeZone
- Java.util - TreeMap
- Java.util - TreeSet
- Java.util - UUID
- Java.util - Vector
- Java.util - WeakHashMap
- Java.util Package Extras
- Java.util - Interfaces
- Java.util - Exceptions
- Java.util - Enumerations
- Java.util Useful Resources
- Java.util - Useful Resources
- Java.util - Discussion
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Java.util.Timer Class
Introduction
The java.util.Timer class provides facility for threads to schedule tasks for future execution in a background thread.
This class is thread-safe i.e multiple threads can share a single Timer object without the need for external synchronization.
This class schedules tasks for one-time execution, or for repeated execution at regular intervals.
All constructors start a timer thread.
Class declaration
Following is the declaration for java.util.Timer class −
public class Timer extends Object
Class constructors
Sr.No. | Constructor & Description |
---|---|
1 | Timer() This constructor creates a new timer. |
2 | Timer(boolean isDaemon) This constructor creates a new timer whose associated thread may be specified to run as a daemon. |
3 | Timer(String name) This constructor creates a new timer whose associated thread has the specified name. |
4 | Timer(String name, boolean isDaemon) This constructor creates a new timer whose associated thread has the specified name, and may be specified to run as a daemon. |
Class methods
Sr.No. | Method & Description |
---|---|
1 | void cancel()
This method terminates this timer, discarding any currently scheduled tasks. |
2 | int purge()
This method removes all cancelled tasks from this timer's task queue. |
3 | void schedule(TimerTask task, Date time)
This method schedules the specified task for execution at the specified time. |
4 | void schedule(TimerTask task, Date firstTime, long period)
This method schedules the specified task for repeated fixed-delay execution, beginning at the specified time. |
5 | void schedule(TimerTask task, long delay)
This method schedules the specified task for execution after the specified delay. |
6 | void schedule(TimerTask task, long delay, long period)
This method schedules the specified task for repeated fixed-delay execution, beginning after the specified delay. |
7 | void scheduleAtFixedRate(TimerTask task, Date firstTime, long period)
This method schedules the specified task for repeated fixed-rate execution, beginning at the specified time. |
8 | void scheduleAtFixedRate(TimerTask task, long delay, long period)
This method Schedules the specified task for repeated fixed-rate execution, beginning after the specified delay. |
Methods inherited
This class inherits methods from the following classes −
- java.util.Object