File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Scheduling for a simple Java applciation

 
Madulika Reddy
Greenhorn
Posts: 10
  • 0
  • 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
 
Gregg Bolinger
GenRocket Founder
Ranch Hand
Posts: 15302
6
Chrome IntelliJ IDE Mac OS X
  • 0
  • 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.
 
Ulf Dittmer
Rancher
Pie
Posts: 42966
73
  • 0
  • 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
  • 0
  • 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
Pie
Posts: 42966
73
  • 0
  • 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).
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic