• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

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

 
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 140
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i actually need my class file to run at a specific time during the day.
 
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ?
 
Ranch Hand
Posts: 299
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 1170
Hibernate Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 171
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Hibernate Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 342
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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....
 
Never trust an airline that limits their passengers to one carry on iguana. Put this tiny ad in your shoe:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic