This week's book giveaway is in the Performance forum.
We're giving away four copies of The Java Performance Companion and have Charlie Hunt, Monica Beckwith, Poonam Parhar, & Bengt Rutisson on-line!
See this thread for details.
Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How do I send mail withour user intervention?

 
Faye Abdon
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1140
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Faye Abdon
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1140
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Make sure that you have mail.jar and activation.jar files in your classpath.
 
Sri Ram
Ranch Hand
Posts: 118
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 308
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 79
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic