
This method is used in cases where the task is to be executed repeatedly after a fixed time period. This method takes three arguments: the first again being the task which needs to be scheduled, the other is the Time at which the task needs to be executed for the first time, and the third argument is the time period after which the task needs to be executed again. #schedule(TimerTask task, Date firstTime, long period) This method is used in cases where the task is to be scheduled only once. The scheduling method takes in two arguments: the first one is the task which needs to be scheduled, and the second one is the time at which the task needs to be scheduled to be executed. #Timer Class Methods #schedule(TimerTask task, Date time) Note: All these schedule methods are public, and they do not return any value. Now, let us have a look at the various schedule methods which belong to the Timer class. Īnd for the task which needs to be scheduled, we use the following package. The packages to be included while working with the timer class are the following. In this case, a timer class is created whose associated String has a name specified, and the thread may be working as a Daemon thread. This is used to create a timer whose associated thread has a name specified.

If this is so, the isDaemon returns a true value. Here, a new timer is created whose thread may be working as a Daemon. The following constructor is used to create a new timer whenever an object of Timer class is created with no arguments passed to it. Let us have a look at the types of constructors of the Timer class. The Timer class contains overloaded constructors in its body. Now, whenever we create an object of the Timer class, its constructor will be called.

#Java itimer code#
Therefore, It is okay to write the above code as follows. Therefore, the declaration of the Timer class is as follows: public class Timer extends Objectīut, by default, as every class inherits from the Object class, there is no need to mention the Object class in is a declaration. The Timer class, like all the other classes, inherits from the Object class.
