Win a copy of Practice Tests for OCP Java 17 Certification Exam (1Z0-829) this week in the OCPJP forum!
  • 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Liutauras Vilda
Sheriffs:
  • Rob Spoor
  • Junilu Lacar
  • paul wheaton
Saloon Keepers:
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
  • Scott Selikoff
Bartenders:
  • Piet Souris
  • Jj Roberts
  • fred rosenberger

Help: email broadcast thread problem

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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!
Thanks,
Victor
 
pie. tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic