Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

need an application to run at a particular moment in the day

 
Sarah Gaikwad
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I need to schedule a java application to run at a particular point in the day. I am aware of the Timer & Timer task classes,but am not sure/confident abt using it.
If anyone of a good way of doing it plz do let me know
i desperately need to know
thanks in advance
Sharun
 
eammon bannon
Ranch Hand
Posts: 140
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Don't know if this is just for running on Windows? If it is just add it as a Scheduled Task in the OS.
 
Sarah Gaikwad
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i actually need my class file to run at a specific time during the day.
 
Steve Leach
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You could give your java class a "main()" method, and then invoke it using the OS scheduler as an application.
Alternatively, have an application that creates a new thread. The thread will check the time and then sleep for a while. If the time is appropriate it can do it's stuff. If you do this, you should set a "date last run" variable so that it doesn't run twice on the same day.
Does this help ?
 
Brian Pipa
Ranch Hand
Posts: 299
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I recently started using a 3rd party library called Quartz and it is GREAT!
http://www.quartzscheduler.org/quartz/
It's free, open-source, and is VERY well documented. I highly recommend it. In your case, you would just have to create a new class that extends Job and in the execute() method does your work or just calls yours class. Then you setup a Trigger with the settings for the time you want it to run. Then you add those to the Scheduler tell the Scheduler to start.
It's really simple - give it a try. Read the tutorial they have online.
brian
 
Mr. C Lamont Gilbert
Ranch Hand
Posts: 1170
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is a feature of the operating system. Otherwise you program must run continuously, and only fire certain methods at the appointed time.
Both windows and Linux have facilities to run programs at certain times. That is what you need.
 
Geoffrey Falk
Ranch Hand
Posts: 171
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Write a program to run as follows:
1) Calculate the difference between the start time and the current time
2) Sleep for that amount of time
3) Start doing its thing.
Geoffrey
 
Mr. C Lamont Gilbert
Ranch Hand
Posts: 1170
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Geoffrey Falk:
Write a program to run as follows:
1) Calculate the difference between the start time and the current time
2) Sleep for that amount of time
3) Start doing its thing.
Geoffrey

Not the preferred way to do this. Preferred way is to use the OS facilities. That way you have better error handling and consistency. Your program must keep checking the clock else your time count will be off when your program gets preempted. No need to keep program in RAM when its not needed. TSRs sucketh.
 
Ben Wood
Ranch Hand
Posts: 342
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I agree, leaving a Java programme running constantly in order that it can do something at a particular time is not really good practice. If you're using windows for example, write your Java class complete with a main() method.
Then you can simply create a .bat file containing the java command to run the application.

Now in windows, using 'scheduled tasks' you can set the batch file to run once a day or whatever and your Java program will run.
I think
 
frisode jonge
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Depends which environment this needs to run. On backend unix systems, it usually works with a cronjob. just do a google search for this. This can run at any time you want.
Then create an executable jar, with the right manifest and main class and there you go....
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic