Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Junilu Lacar
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Knute Snortum
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Ron McLeod
  • Carey Brown
Bartenders:
  • Paweł Baczyński
  • Piet Souris
  • Vijitha Kumara

Scheduling for a simple Java applciation

 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • 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
  • 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: 43011
76
  • Mark post as helpful
  • send pies
  • 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
  • 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: 43011
76
  • Mark post as helpful
  • send pies
  • 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).
 
You are HERE! The other map is obviously wrong. Better confirm with this tiny ad:
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!