Is it possible to run a code at certain time period? - java

So, I am writing a Java code where I want the program to take content from the web every monday 12 am.
I found SO many answers telling me how to run a program for certain amount of time. I want to run the program and execute every monday morning.
I want to know if any one has ANY idea where to start?
I found of AlarmManager for android applications (which is sort what I want) but I want it for Java program not application.
Or is this even possible?

Sure! If you are on linux or mac, just set up a cronjob to run at 0 0 * * 1
It'd be something like:
java MyScript.java
as the task.

Try this:
Scheduled Tasks With Cron for Java

http://quartz-scheduler.org/ is the standard tool to setup cron-like jobs

Yes it is using Windows Task Manager!

Related

Is there a way to get a Java program to run during a certain time of day?

I am just curious on if it would be possible to write a java application and then have it run automatically during a certain time of day??
For example: If I had a program that would like open a text file and write the current date in it and then close. Would it be possible for me to get it to run at say 8:00 A.M. everyday without me having to run it?
The simplest solution would be to use a batch job scheduler, eg. cron on *nix or Windows scheduler. It can easily trigger your program to run at the desired time.
Otherwise, you could write a long running Java program that detects when 8am has rolled around and perform your desired action.
Also you can check janos♦'s answer below to Executing a task at a particular time in the morning using ScheduledExecutorService, hope it will help good luck...
https://codereview.stackexchange.com/questions/63520/executing-a-task-at-a-particular-time-in-the-morning-using-scheduledexecutorserv

How to program Java app to execute everyday at a certain time?

My computer is turned on 7/24. However, it does gets locked. I have an app that includes Selenium and other APIs. I need it to execute everyday at say 6 AM. Is there any way I could do this. I heard about the Windows Scheduler. Is there any way to make it execute on its own? Or waht is the best way to do this. (I have Windows 7)
What you need is a Quartz scheduler. Please find the link for the same : http://quartz-scheduler.org/
Using quartz scheduler you can schedule a job to run everyday at 6 AM using cron expressions. You can create cron expressions using www.cronmaker.com

Execute code when system time reaches a specific time [duplicate]

This question already has answers here:
run a Java program in specific time
(2 answers)
Closed 9 years ago.
How can i implement code to do something when a specific system time is reached?
The only solution i have thought of is using a timer to "tick" every few minutes or hours to check if the specific time has been reached.
Are there any other better solutions ?
Thanks.
sorry if i had not been clear, i would be implementing the code inside my Java program, it is to clear records of a log before a new day is coming and save the records.
Example: Clear the current records and save these records at 23:59.
In pure Java, there is a Timer class. This is useful if you have a program running already. Or you are running a web app that is always up.
Another alternative is to use operating system (UNIX cron) and have it start the Java program at that time. This is useful if you don't meet the conditions for Timer.
You can just make a timer with a long duration. If the trigger time will be 350 minutes from now, there's no point having a timer poll every minute to see if the time is reached. Just set your timer to 350 minutes. Once it fires, remove the timer. This is called a one-shot timer. I can't answer how to specifically do this in Java, unfortunately.
If you are using Unix-like systems have a look at cron
If you are on Windows have a look at What is the Windows version of cron?
if i understand your question correctly, for unix, you can put your code in crontab and schedule it to run at specific system time. while for windows, you can use task scheduler. this is how we do it to run specific test scripts for nightly builds.
Quartz Scheduler Framework is an enterprise class framework that can be used as a Timer.
did you try Quartz Scheduler? , it is a powerful and advance scheduler framework, to help Java developer to scheduler a job to run at a specified date and time.click here for more
I think java.util.concurrent.ScheduledExecutorService is enough.

Java/Database project automation

I have a Java/Database project in Netbeans that I would like to run once a day at a set time. I am using Derby for the database driver. I am trying to automate a process.
How can I 'schedule' this program to run at specified times?
How can I customize this to keep running until a certain criteria is met?
Say my criteria is that It has to populate 500 rows in the database. (So say at the scheduled time it runs it can only populate 400 rows, then maybe 2 hours later it tries running again to fill the last 100 rows)
Lastly, what are the best practices of automation and scheduled tasks?
How can I 'schedule' this program to run at specified times?
This can be done one of two ways, depending on your operating system - write a job that kicks off the java program at the intervals you need. You may then hook up the job to be started off on start up.
In Linux you can accomplish this with a cron job or so. On windows you may refer to this http://support.microsoft.com/kb/308569.
You may also program the scheduler into your java program using http://quartz-scheduler.org or http://www.sauronsoftware.it/projects/cron4j/ .
How can I customize this to keep running until a certain criteria is met?
This is perhaps best established from within your program, although it is hard to give you directions without much info.
Lastly, what are the best practices of automation and scheduled tasks?
Depending on your application architecture, scheduling and automation can be handled either from within the app or get support from the operating system. The criteria depends on how much control the application needs, which platform makes scheduling easy etc.
Hope this helps.
Quartz is a scheduling project for Java. I have used it in many projects and find it to be very intuitive.
It may be a little over the top for what your after but worth a look anyway.
You can make use of Timer for scheduling the events & the events/task must be implemented using TimerTask

Where to get 1440 free cron jobs a day?

I'm making a program for my own use.
In this program, I need to set up cron job. The cron job should run every minute (24 hr * 60 mins = 1440 times). Thus, I'll need to set up a cron job with a frequency of 1 minute.
I think Google App Engine gives free cron job. But I'm very new to it. I downloaded the java SDK and read the document but understood nothing :( So, I can't use Google App Engine.
Is here any other free service like Google app engine which but with easier inferface???
All I want is a cron job with 1 minute frequency
Please help/suggest me...
Thank you
Just install linux.
If this is a java app, then you can use Quartz, right? This way you can control what to do when the job fails (like cleaning up certain resources, sending emails, etc).
Maybe you want to use a service like setcronjob.com.
This lets you specify a URL that will be triggered periodically (according to the cron pattern you choose).
Of course, you still need to have a server somewhere to host the URL and implement the actual task there.
You can do this in App Engine - see the cron docs for details. In order to provide any more specific help, we'd need to know what you want that cron job to do, precisely.
I had the similar need. Ended up testing a whole bunch of scheduling services. Check out cronservice.co.uk/new/,
setcronjob.com or mywebcron.com. I ended up using the scheduler.codeeffects.com because of their set of features and the interface. Google for others, there are tons services like this. Most are free or give free stuff. Sorry for the late reply, but I thought this might help.
To schedule a job in Java, use cron.xml
Python uses the more terse cron.yaml format.
In both cases, it's actually quite easy to use, you can schedule jobs, with the following actual description and Google App Engine will understand what it means:
every 12 hours
every 5 minutes from 10:00 to 14:00
2nd,third mon,wed,thu of march 17:00
every monday 09:00
1st monday of sep,oct,nov 17:00
every day 00:00

Categories

Resources