I have written a Java program which retrieves Google data till present date using Google Analytic API and export it as CSV file. I want this program to run daily so that data in the CSV file will be up to date. How can I achieve this?
You can use the Windows Task Scheduler (see tutorial) to start any program; for Java, you will probably want to create a batch file to run your Java program, then use the Scheduler to run the batch file. The Scheduler provides a "Create Basic Task" wizard for setting up these schedules.
You can also use an executable JAR instead of a batch file, provided that Windows has a file association between JAR files and Java.
You may need to specify the start directory if your task performs IO - see this thread.
Schedule Via Java
Use a ScheduledExecutorService and the method scheduleAtFixedRate with a TimeUnit of Day. Your program will wait a day and then do what it has to do.
Of course your computer has to be on. If that is an issue, it might be better do something like this using Google App Engine.
Have a look at Windows Task Scheduler. Task scheduling can be found under all programs -> accessories -> system tools -> scheduled tasks.
Related
I have a Java - Spring application. I want to set up a feature to listen a file location(Folder) and has to process a file as a file get created in this folder.
My plan is to set up a spring quartz cron job which will run in every five minutes and process the files available.
Please suggest me a better approach.
A choice of solution depends on how quickly an appearance of a waited file must be detected.
If it is not urgently and at least 1 minutes would be OK, then your solution using any kind of cron job would be OK too.
If a file should be detected asap, then you must provide a permanent running program, that detects a file in very short intervals. This can be reached by for this task dedicated daemon. If your program has nothing to do during wait time, then it can contain part for the file detection.
If you have moved on to/are on java8, it provides Watch Service API that allows us to monitor file and folder locations.
Have a look at Watch Service API
I have a big xml file that I want to get transferred from c: drive to d: drive at particular time period.
I want to design a Java class to perform a batch job. This would means that the java class will act like a batch job and it will pick the xml file from c: drive and will send it to d: drive at particular time.I want the other time setting and file location specifications to be done in xml file and the rest java class would contain the buisness logic.
Please advise how to achieve this , and also please let me know any of frameworks like Spring or Spring Integration, Spring Batch that might provide any help..!
I am more interested in spring batch!!
I would recommend using your OS scheduler to achieve this. Put your business logic in the Java code any way you want but on windows schedule it with the windows scheduler, on unix use cron.
If you absolutely need Java to be the scheduler as well, look into Quartz.
---- Using Windows Scheduler ----
First, create a batch file to kick off your java code:
myjavarunner.bat:
java -classpath <myclasspath> com.silly.project.ClassWithMainMethod <arguments>
This is not strictly necessary, but when working with java, it is often much easier. Then, create a scheduled task. Click the start button -> Control Panel -> Administrative Tools -> Task Scheduler. Click the Action menu -> Create Task. Fill out all the forms and let er rip.
A simple start would be using a Timer to schedule the periodic job and a TimerTask to implement the business logic.
I have a table in database with users and their expenses for traveling. I am using GWT and want to run a code once a month, that would query the database and send bills as PDFs to customers. I know how to create PDFs and send emails from servlet.
How to run a program in java (or some other script if it isn't possible with java) that would run once a month?
Tnx
Unix and derivatives: use cron -> http://en.wikipedia.org/wiki/Cron
Windows: use task scheduler -> http://support.microsoft.com/kb/308569
If you want to get fancy and do it purely in java: -> http://www.quartz-scheduler.org/, but do consider OS scheduler first.
you have many choices.
If you are under Unix, the simpliest solution is a batch scheduled with a crontab.
If you prefer a 100% java solution, the Quartz framework is a robust a easy to setup solution.
To avoid "re-inventing the wheel" I suggest using http://www.freshbooks.com/ and tying your app into their API to send your bills. You can easily set up recurrence as a billing option so that the bills get re-sent (along with reminders) each month. The user can then grab the PDF version of their bill.
I want to run my java program in regular interval , lets say, in every 3 hours. I am thinking to write a .bat file and put command to call java class. But what is the best way to run .bat regularly in windows xp. Thanks in advance. I dont want to use third party tool.
Windows scheduled tasks are built for exactly that purpose.
You can run things on multiple schedules (so you can get your every-three-hour behaviour) and you can get your code to run whether or not logged in.
The multiple scheduling is a bit tricky. You basically set it up as a daily task to start with but, near the end, it will ask you if you want to do advanced features.
Select yes then you can set up multiple schedules at that point.
If you want a pure Java Based solution you can try QUARTZ SCHEDULER. But as paxdiablo already mentioned, Windows Task Scheduler will do that as well.
I have developed a Java application. I want to run it as a background process.
It should not be displayed as Running Application in task Manager, but it should be displayed in Processes List.
Help me out.
Regards,
Jigar
I've edited your question since it's a pure windows issue.
I would suggest you to take a look at ways to run your java application as a windows service.
In addition to Command Prompt option given by Rafael Roman, we can also schedule task through Control Panel -> Scheduled Tasks -> Add Schedued Task. For more info:
http://technet.microsoft.com/en-us/library/cc738106(v=ws.10).aspx
There's no need for complex solutions.
use the at commando and create a bat that runs your program.
type in any cmd windows:
at 10:00 c:\run_my_script.bat
remember to replace 10:00 to a time 1 minute after the current time of your machine