Satish Sharma
Satish Sharma

Reputation: 3294

Spring task scheduler Multiple Instances on multiple machines detection

I have made an Spring Task Scheduler services for sending e-mails at particular condition. This service is running on multiple machines.

If one machine service sends the e-mail then I have to stop the other service for sending the email.

How can I detect this without using persistent storage flag that one machine service has executed its e-mail code?

Upvotes: 4

Views: 737

Answers (1)

Marcel Stör
Marcel Stör

Reputation: 23535

You have basically 3 options:

  • Use a shared data store of some form (e.g. data base) that all nodes connect to. That's what we do usually.
  • Make the nodes "talk to each other" so a particular node could the check the state of its peers before sending email. For this you could use JGroups.
  • Have your email service run on only one of the nodes.

Upvotes: 2

Related Questions