Win a copy of The Way of the Web Tester: A Beginner's Guide to Automating Tests this week in the Testing forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Help: email broadcast thread problem

Victor Seal
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, experts, please help!
I need to implement several email broadcast schedulers: some run every 24 hours, some run every 30 days, or 2 weeks, etc.
All these schedulers are started (that's to say, threads are running) in the init(ServletConfig) method of servlet. when the web app is deployed in the Tomcat. The problem is all the schedulers use the email
server and when one hugs the mail service, others can't use it. And other applications also use the same email service, but in the first version, the email service is not synchronized. And problem typically exists the first time all scheduler are started, because all of them need to compete for email service.
I am thinking 2 options:
1. All schedulers implement Runnable. The first time they start running, say if I have 3 broadcast schedulers, the 1st directly uses
email server without waiting, the 2nd Sleeps 2 minutes first, and the 3rd sleeps 4 minutes. But the problem is, as we have more and more users to broadcast,
the 1st scheduler may not be able to finish sending all emails in 2 minutes. So hard coding Thread.sleep(120000) is not a good idea. (this timeout could be read from a property file, but it is still not adaptable)
2. All schedulers extends TimerTask. Then use a Timer object to schedule the TimerTask. But this still needs delay and period as parameters. From the API, it is thread-safe, but I never used it before.
One principle in my application I have to follow is these background threads have to yield to other applications invoked by users in case they compete for email service.
Any suggestions or ideas will be greatly appreciated!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic