-3

I have a web service deployed at two server which uses @Schedule to automatically send emails. How can we prevent duplicate emails sent because they are deployed on two severs. Can we use database lock?

  • You could perhaps provide a bit more detail... – BK435 Apr 06 '15 at 23:26
  • your answer is here: http://stackoverflow.com/questions/15573257/does-mysql-support-atomic-select-and-update-together, or here: http://blog.tekerson.com/2008/04/08/using-a-mysql-table-as-a-thread-safe-queue/ – pala_ Apr 06 '15 at 23:37

1 Answers1

0

My suggestion is to check if either one has been sent. This can be done by adding the email to a list.

Then, checking if that email is on the list at a later point

EXAMPLE:

List:

1: john@joe.com
2: joe@john.us
etc.

Java:

if([get the list] has email)
{
     don't send it
}

Hope I understood you correctly. :) Goodluck.

Colin Koenig
  • 65
  • 1
  • 3
  • 15
  • and what happens when both services check the list at the same time, and both services get the all clear? – pala_ Apr 06 '15 at 23:36
  • Well, in this case the one to first check it would also put it on the list. So only one would get the "All-Clear". There is never a point when both are checking due to the fact one is putting it down on the list as it comes up. I might have been unclear about this. Thanks for pointing it out. – Colin Koenig Apr 06 '15 at 23:39
  • Hi Colin, thanks for the reply,but to be more specific, the same service is deployed at two server which access the db to retrieve the emailid at the exact same time. Since the web service are replica of each other. They will have the same code. The above implementation may not be feasible. – pratik hada Apr 06 '15 at 23:40
  • @ColinKoenig you are missing some vital information, and that is either atomic transactions, or row locking. Without them, there is no way to guarantee that service 1 updates the row before service 2 has also performed the same check – pala_ Apr 06 '15 at 23:41
  • this question is basically about multi-threaded access to a queue. the threads are just distributed. – pala_ Apr 06 '15 at 23:43