• Post Reply Bookmark Topic Watch Topic
  • New Topic

Sending Email in background

 
Anurag Dhiman
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • 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
  • Quote
  • Report post to moderator
Sorry!
From next time I'll be very careful!
 
Ulf Dittmer
Rancher
Posts: 42970
73
  • Mark post as helpful
  • send pies
  • 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: 42970
73
  • Mark post as helpful
  • send pies
  • 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
  • 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
  • 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: 42970
73
  • Mark post as helpful
  • send pies
  • 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.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!