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(); taskScheduling.proceed(); } 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 taskTimer.schedule(timerTask,5000); }}/*
Expected output:
[root@mypc]# java TaskSchedulingIn run() method*/