Reliable way to create scheduler for executing Java program in Windows - java

I have a task in which, I have monitor a folder for new files and upload its content to database. For this, I have written a Java Program, created an executable JAR and scheduled it for execution after fix interval i.e after 5 min. using Windows Task Scheduler on Windows 7.
I have to ask about reliability of this approach. How reliable is Task Scheduler? Is there any better approach like creating a windows service ,etc by which I can schedule my Program/ JAR.
Any suggestions would be appreciated.
Thanks!
Best Regards,
Kunal

Take a look on Quartz
Quartz Scheduler is a Java-based open-source job scheduling service which is used in most of the applications to schedule their timely jobs.

Related

Distributed CRON in Kubernetes

distributed CRON in Kubernetes is still a work in progress (https://github.com/kubernetes/kubernetes/issues/2156).
What do you use for CRON jobs in Kubernetes today?
Do you recommend any solution that works well with Spring/JVM-based services? Spring/JVM startup time is quite high and if CRON scheduler started a new JVM for each job, startup time might be much higher than time of actual work - is there any solution that could run the job in existing JVM?
Thank you,
Jakub
I think Mesos Chronos is still ideal solution.
I wrote a small Go app that functions like cron but writes log info to stdout (no email!) and can be built into a static binary for easy containerization.
I built kubectl from source as a static binary and included it in the image (it may be a static binary in the most recent releases). Kubectl will automatically look for the service account token/certs in /var/run/secrets/kubernetes.io/serviceaccount/ so you should be good to go unless you're not using the default service account.
I then set up a crontab to run kubectl to create a job at the period that I wanted. The crontab and yaml files for the jobs can be mounted as a secret. You can either use conf2kube or some other way of generating the secrets. I wrote a simple python script.
It's totally a workaround until there is proper support but I hope that helps.
I'm using cron jobs in kubernetes with java, each job launches a new JVM, so no. No reuse here.
To reuse you must jave something like a webapp always running and schedule jobs to run inside this already running app.

Creating a background process using java

I want run a background process at a specific time. I want that process to be run on the server even without running the application from End-User side. The application is made using Spring. Please suggest how to approach for it.
Thanks and regards
Souvik
I depends highly on what platform you are working on, and what you want to achieve.
If it is a simple application, that you simply want to invoke that on specific time, then you can use scheduling tools available on your platform, for example, crontab for Unix, or scheduled task (at) for Windows.
If you want the application to be run as a daemon process, and the application itself will handle the scheduling, then you need to solve two problem: 1. create a daemon process (aka system service), and 2. doing scheduling in Java.
For problem 1, there are already answer for it. Just have a search on Google on "Java System Service" will give you some other useful tools too, like Java Service Wrapper
For problem 2, there are a lot of way to perform scheduling in Java. You can do it by built-in Timer etc, or using scheduling library like Quartz

Windows Scheduler Vs. Java TaskTimer

I have a .bat file in a Windows machine that starts our program by calling a main class of a Java executable(.Jar)
Now I need to run this every 30 mins.
I gone through several ways of doing it, but unable to decide which is better.
Scheduling through Windows scheduler or Using Java Timer. Which one to choose?
I want only one instance of the process running. If the previous process doesnt complete within 30min, i could wait.
Please let me know what to go for, based on my use case.
Thanks in advance.
You're better off using the Windows Scheduler. If there's a real risk of the process taking too long, you can create a file, or open a socket while the process is running and when another one tries to start up, it can detect that and simply quit. This would make it "miss" the 30m window (i.e. if the first job started at 12 and finished at 12:35, the next job would not start until 1).
But this way you don't have to worry at all about setting up long running processes, starting and stopping the java service, etc. The Windows scheduler just makes everything easier for something like this.
TimerTask is not a scheduling system, it is a library that provides tools for in-app scheduling. Seems that for your use-case you need a the system: you need it to run whether or not your app is running, you need reporting, etc. Windows Scheduler (or cron on unix/linux) is more appropriate for your needs.

Schedule task to run once per week in java

What would be the best way to schedule an event to run every Monday at 00:00?
Note though the app is running 24/7. So OS based schedulers such as cron are not needed.
You could embed a Quartz Scheduler in your Java app if it's a long running app. Quartz is a very flexible/powerful scheduler that can be configured in many ways.
Alternatively, if you simply want to run a Java process at a particular time then you should look at cron.
Edit: Given that your app is 24/7 (noting comments above), Quartz is definitely the way forward.
I think cron4J may be your best bet. You can then configure it to run at ceratin times.
Us the OS scheduler; either cron, Windows task scheduler or similar

Most efficient method to schedule java application to run daily

I have a java application which downloads a file from an FTP server and I need it to run daily. I was just wondering what the best method to schedule it to run would be. The options I am currently considering are the Windows scheduler and Java timer task.
At the moment I have the windows scheduler pointing at a batch file which runs my program.
If anybody has any knowledge in the area I would appreciate to hear from you!!
Look at AT TASKS on windows and CRON JOBS on unix. These can run your Java program.
You should also take a look at Quartz which is a Java-based job scheduling system.
You can also get help from this link.
Why don't you use #Schedule abilities of EJB 3?
If your server is not EJB 3 - capable, use Quartz, Timer and TimerTask classes.

Categories