• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Scheduling for a simple Java applciation

 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
All,
We have a java program which sends a email through smtp server. We want to schedule it once in a week.

Please advise on any options.

Also I heard J2EE schedulers which are used to schedule a task. Please suggest some.

Regards,
MReddy
 
Ranch Hand
Posts: 15304
6
Mac OS X IntelliJ IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you need a Java solution I'd recommend Quartz. Other options would include a cron job if running in Linux or a scheduled task if running windows.
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Quartz is a very good package, but it may be more than you need. Java comes with the built-in java.util.Timer and java.util.TimerTask classes, which have much less functionality, but may be sufficient for what you're doing.
 
Madulika Reddy
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Dittmer,
We are using WAS for the production. I heard that when using the J2EE app server and Timmer classes there will be some thread issues as both creates threads. Could you advise on this. Our application needs a report to sent out at fixed times. and one more advise, how much effort does it take?

Thanks
Madhulika
 
Ulf Dittmer
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I can't imagine why adding a thread of your own would create problems with threads the app server creates. It certainly should not, and -WAS being a serious and expensive piece of software- it better not. Using Timer and TimerTask is easy; I picked it up by simply studying the javadocs, although I don't remember the details now.

One thing to look out for is that threads can be scheduled at fixed times, or fixed time intervals. You need to set that when creating the thread. In the former case, the thread is run, e.g., every day at 3pm, no matter how long it takes to execute. In the latter case, it is run every, e.g., 24 hours after it last finished execution. So if it takes one hour to run, the second run will be started 25 hours after the first start, not 24 hours later (there are 24 hours between runs).
 
Doe, a deer, a female deer. Ray, a pockeful of sun. Me, a name, I call my tiny ad ...
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic