aspose file tools*
The moose likes Servlets and the fly likes How do I send mail withour user intervention? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "How do I send mail withour user intervention?" Watch "How do I send mail withour user intervention?" New topic
Author

How do I send mail withour user intervention?

Faye Abdon
Greenhorn

Joined: Nov 14, 2005
Posts: 3
Hi! Any help would do.

The requirement is to have a java application that reads a file from a local directory and then send and email if the file has been found. Only this does not require any user intervention and only do the task at, say, every 7pm.

* I have already made the program that sends out mail and file reading.

Does anyone here have encountered this? Thanks so much for the help.
Mani Ram
Ranch Hand

Joined: Mar 11, 2002
Posts: 1140
Check java.util.Timer and java.util.TimerTask classes. Using these classes you can schedule a task. It's quite simple and easy to understand.


Mani
Quaerendo Invenietis
Faye Abdon
Greenhorn

Joined: Nov 14, 2005
Posts: 3
Thanks Mani. I have tried the Timer now Im facing another problem in my program that sends the email. It's giving me NoClassDefFoundError: com/sun/mail/util/SharedByteArrayInputStream. I have the j2ee.jar inside. And I dont know what could be the otherpossible problems. Thanks for the help.
Mani Ram
Ranch Hand

Joined: Mar 11, 2002
Posts: 1140
Make sure that you have mail.jar and activation.jar files in your classpath.
Sri Ram
Ranch Hand

Joined: Oct 03, 2005
Posts: 118
Y go into that much trouble.
If this Program must run only on server machine then, cant u schedule a job to run at a particular time.
jiju ka
Ranch Hand

Joined: Oct 12, 2004
Posts: 306
If this application is needed a 24/7 support in a moderate enterprise, you need to check with your enterprise whether they have any mutiplatform schedulers already implemented.

If you use a timer a jvm should be running all the time. That means if the file extraction and mailing process takes five minutes you will be waisting resources for rest of the time. This is OK if you don't have other alternatives.

If you usea multiplatform scheduler you may write a batch script which runs your mailing and extraction program. You may configure the scheduler to trigger the batch script for particular time.

The point is regardless of running platform the scheduler should run 24 hours. So only a stable platform should be chosen for running scheduler. By using a timer in java you are making a custom scheduler.
Rajesh Agarwal
Ranch Hand

Joined: Aug 01, 2005
Posts: 79
It could be done like some thing below

Timer timer = new Timer(true);
standAloneTimer = new StandAloneTimer();
timer.schedule(standAloneTimer, 0, 30000);


Where StandAloneTimer is the Class which would run every 30 Secs and it extends TimerTask and overrides the run method.
 
wood burning stoves
 
subject: How do I send mail withour user intervention?