I have a Virtual Dedicated Server, how can I run an application periodically (ie: every Monday - 19:00). I mean, the application starts automatically at a given time.
Is there any way to do it with Java, Ajax, PHP? (sorry, I'm noob)
You can create scheduled tasks in windows and cron jobs in linux/*nix like systems. If you can run programs on the server and want to use java you can use timers to schedule your task - here is a simple example.
I'm assuming your server is linux.
You may be able to do this with webmin.
You will need to use command line to install webmin and setting up a crontab from command line is really not that hard to do.
Here is a tutorial for crontab.
http://www.linuxweblog.com/crotab-tutorial
What OS does the server run?
Related
I have a java program that should run on a Windows machine. It should run "forever", i.e. when the JVM or the program crashes, it should be restarted. When the computer is restarted it should also be restarted.
I saw advice to wrap the program as a "Windows service", but the tools I found seem to be either costly, complicated or outdated.
Can somebody describe me a straightforward way to achieve the desired behaviour?
For the part where you want to start the program after restart you can create a simple batch (.Bat) file and u can put that file in the startup folder.
Also you can use the same file for running the program when it crashes. you can use tasklist command and check if your java program is running and if it is not .just start the program.
Just check our windows batch this is one of the best things you can get everything for doing anything on windows without anything expensive
Yet Another Java Service Wrapper is a tool that easily wraps your Java program into a Windows service. Just start the program, note down the PID and enter it into the wrapper. Two things, which are probably universal to services, should be noted:
For connection to the network, you need to specify an account with the necessary rights.
Connected network drives are not available.
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
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.
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.
What's the best/easiest way to run periodic tasks (like a daemon thread) on a tomcat/jetty server? How do I start the thread? Is there a simple mechanism or is this a bad idea at all?
If want to keep everything on java side, give a look to Quartz.
It handles failover and fine grained repartition of jobs, with the same flexibility of cron jobs.
It's okay and effective to stash a java.util.Timer (or better yet ScheduledExecutor) instance in your ServeletContext. Create it in a Servlet's init() call and all your servlets can add TimerTasks to it.
One general purpose way which works for many systems is simply to have a cron job which performs a periodic wget against your app.
I can't answer the tomcat/jetty stuff, but I've done similar things with Python based web apps.
I normally just run a separate app that does the periodic tasks needed. If interop is needed between the website and the app, that communication can happen through some sort of API (using something like XML-RPC/unix sockets/etc) or even just through the database layer, if that's adequate.
Hope that helps.
If you want to use a cron job but don't have administrative access to the development system, you can do a user crontab by executing the command:
crontab -e
It uses vi by default on most systems, but you can change it to the editor of your choice via:
export EDITOR=/usr/local/bin/my_editor
Then, executing the crontab -e command will launch your crontab file in your editor. Upon saving, the changes will be committed back into the system's cron.