4

I have a java application which has been scheduled to run once every night at a set time. The application sends e-mails if a condition is met. All the scheduling code is in Java and I am not using any of Amazon's features to schedule it. This application has been deployed on an EC2 instance and it sits behind an elastic load balancer. Based on the load, additional nodes could be added. My java application gets replicated to other nodes as well and the nightly job executes on all instances.

Is there a way by which I can make a single node execute this job?

Thanks.

  • Are you using some sort of scheduling library or framework, or is it something custom that you created yourself? – Mark B Aug 19 '16 at 00:43
  • I'm using Spring to schedule it. I'm annotating the function with @Scheduled annotation and passing it some cron configuration. So my annotation looks like @Scheduled(cron = "0 0 0 * * ?") – Pravin Umamaheswaran Aug 19 '16 at 14:30
  • Your question is basically a duplicate of this one: http://stackoverflow.com/questions/31288810/spring-scheduled-task-running-in-clustered-environment I suggest reading the answers to that question. – Mark B Aug 19 '16 at 15:15

1 Answers1

0

I'v newer deployed to amazon (and have small experience with Spring) but i see some ways to solve it:

  1. Just use Apache Zookeeper. Create ephemeral-sequential nodes in zookeeper for each node. When i'ts scheduled time and node is first in that queue - remove node from queue, add node again and start your job (Apache Curator Framework has all functionality you need to implement it in your code)
  2. Use Hazelcast queues (same logic). Benefits: hazelcast could be used in embedded mode. Minuses: not sure about hazelcast discovery abilities in amazon, as for my experience - hazelcast is much less stable than zookeeper.
  3. Other way - if you have any "instance id" on each instance you could start job if start time is reached AND instanceId.hashcode() % dayOfMonthNumber == 0