0

So i have a task of creating a program which is given absolute path to exe location and time of the day when that exe is supposed to be run and whole program should be running in background and printing a log with time and date info. Java program should be active in background and should run that exe file tomorrow at the same time. I got this code skeleton from another question here

public static void main(String[] args) {

        ScheduledExecutorService service = Executors.newSingleThreadScheduledExecutor();
        Runnable runnable = new Runnable() {
            public void run()
            {
                // do something;
            }
        };

        // Run it in 8 hours - you would have to calculate how long to wait from "now"
        service.schedule(runnable, 8, TimeUnit.HOURS); // You can 

    } 

Okay i've written a program which works. I now need help with running it in background. I have exported it as .jar file since it will be started from cmd (i've created a bat file too, i think app will be started through bat file). Is there any way i can run the program in background and see a small icon in taskbar which would indicate that .jar file is running in background? For example when running on windows i could click "Show hidden icons" on the bottom right of my taskbar and see a small icon which would indicate that script is running?

Gray
  • 115,027
  • 24
  • 293
  • 354
  • First, I'd look into a scheduling API or if you can't use a 3rd party library, have a like at `java.util.Timer`, which would allow you to schedule a task to be executed at a specific point in time – MadProgrammer Mar 28 '17 at 07:50
  • If you do not have to do this in Java, you should look into Cron (if you happen to be on a Linux machine). Otherwise you are correct, you add your code in the run() method. And if you want to reschedule it I guess you can do that in the run method as well. Set service to final and you can use it inside your anonymous runnable. – UnixShadow Mar 28 '17 at 08:02

0 Answers0