Hi all,
I have a simple program that polls a DB table every so often and sends any mail that the table indicates is pending (using javax.mail). When the mail is sent I delete the DB entry.
I have noticed two potential problems
- There's the potential to send a mail and then something crashes so the DB entry is still there. The next time the mail will be sent again.
- There may be lots of mail to send so I load all the pending entries, send them all, then delete all the DB entries. If some/all the mails get sent, something fails, and the job runs again then it spams many people twice.
This isn't a spam application so I want to try and avoid sending anything twice plus make sure I can never "lose" a message.
This is a general problem I'm sure where there are two physical resources that can't participate in a transaction (DB + something else) so I was wondering what approaches people use to reduce/eliminate the problems for this case and/or the general case.