Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
#!/home/adrian/java/openjdk-11/bin/java --source 11
//Simple CRON Job reimplemented using Java APIs!
import java.util.Date;
import java.util.Timer;
import java.util.Calendar;
import java.util.TimerTask;
import java.time.LocalDateTime;
public class Countdown {
private static class DeleteClassFiles extends TimerTask {
public void run () {
System.out.println(".....running imitation CRON JOB......");
try {
//CRON JOB - Create File
if (new File("JavaIsTheBest.blah").isFile())
System.out.println("File already exists.");
if (new File("JavaIsTheBest.blah").createNewFile())
System.out.println("File successfully created.");
System.out.println("File was not successfully created");
} catch ( ioe) { };
System.out.println("Ending countdown for task......" +;
public static void main (String[] args) {
//It's a shame that Timer/TimerTask doesn't work with the Java8 DateTime APIs!
try {
//Grab Time, Add Time
var dt = Calendar.getInstance();
dt.setTime(new Date());
dt.add(Calendar.SECOND, Integer.valueOf(args[0]));
//Schedule job
var timer = new Timer();
System.out.println("Beginning countdown for task......" +;
timer.schedule(new Countdown.DeleteClassFiles(), dt.getTime());
} catch (NumberFormatException nfe) { System.out.println("Malformed input."); };

This comment has been minimized.

Copy link
Owner Author

afinlay5 commented Jun 26, 2018


Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.