Browse DevX
Sign up for e-mail newsletters from DevX

Tip of the Day
Language: Java
Expertise: Intermediate
Feb 11, 2020

Automation of Tasks

Automation of tasks is a good concept. Consider the example below in which you create a task and schedule it at your convenience to execute the needed actions. There are other types of scheduling as well. Explore them to know more.

import java.util.Timer;
import java.util.TimerTask;

public class TaskScheduling
   public static void main(String args[])
      TaskScheduling taskScheduling = new TaskScheduling();
   private void proceed()
      Timer taskTimer = new Timer();

      TimerTask timerTask = new TimerTask()
         public void run() 
            //Our task action
            System.out.println("In run() method");
      //The below setting will ensure that the taskTimer is executed after 5 seconds


Expected output:

[root@mypc]# java TaskScheduling
In run() method

M S Sridhar
Thanks for your registration, follow us on our social networks to keep up-to-date