• 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:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

Sending Email in background

 
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello Everyone!
I have written a code for sending emails based on time. These emails will delivered 24 hrs and 2 hrs before the specified time. But the problem is when I am running the code code eclipse the emails are going properly but when I am exporting a WAR file and deployed it on tomcat the email is going repeatedly for four times.
For this I have used java Timer class which is keep running in background and if the time difference matched the email status will update in DB after emails sent once. I need your help guys. Please suggests some idea how to prevent email for sending repeatedly. Is this a code problem or Tomcat?

Here is my code snippets
 
Anurag Dhiman
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sorry!
From next time I'll be very careful!
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
We don't know the data that is retrieved from the DB, but since the whole thing is in a loop, I suppose it's possible that the mail sending is triggered many times, depending on the data.

Since the Timer goes out of scope I'd assume that it's possible that it will stop working at some random moment because it is GC-ed (I guess that they're not eligible for GC because the JVM holds references to them even if the application code does not).
 
Ulf Dittmer
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What type does "mailStatus" have in the DB? Line 55 treats it as string, whereas line 115 treats it as integer.
 
Anurag Dhiman
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Ulf Dittmer!
Seems a valid reason in your comment. I'll do some more research on it get back to you!
 
Anurag Dhiman
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
mailStatus is a varchar type in DB so I think it can handle line 115 without any problem!
 
Ulf Dittmer
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

mailStatus is a varchar type in DB so I think it can handle line 115 without any problem!


It looks like sloppy coding to me, though.
 
sunglasses are a type of coolness prosthetic. Check out the sunglasses on this tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic