Created
June 26, 2018 09:22
-
-
Save afinlay5/23fcd05353e2edd1dcaa89478ec994b8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/home/adrian/java/openjdk-11/bin/java --source 11 | |
//Simple CRON Job reimplemented using Java APIs! | |
import java.io.File; | |
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."); | |
else | |
if (new File("JavaIsTheBest.blah").createNewFile()) | |
System.out.println("File successfully created."); | |
else | |
System.out.println("File was not successfully created"); | |
} catch (java.io.IOException ioe) { }; | |
System.out.println("Ending countdown for task......" + LocalDateTime.now()); | |
System.exit(0); | |
} | |
} | |
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......" + LocalDateTime.now()); | |
timer.schedule(new Countdown.DeleteClassFiles(), dt.getTime()); | |
} catch (NumberFormatException nfe) { System.out.println("Malformed input."); }; | |
} | |
} |
Author
afinlay5
commented
Jun 26, 2018
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment