How to run a planned method in a cluster for one Node and for all?

I have Glassfish 3.1.2 that works in a cluster and EJB 3.1 application. And I need two kinds of scheduled methods in my application:

  • one view that runs only once (on one node) once a day
  • and another view that works on all nodes (every 1-2 minutes). They DO NOT need to start synchronization! The requirement is that this view be executed on each node.

I don’t know how to start with this cluster problem, is this possible with @Schedule (and how) or do I need something else?

+6
source share
2 answers

I ran into the same problem (need one cluster timer and per node timer) and ran into this question. So, for everyone who is interested in:

If you declare a timer using @Schedule (..., persistent = true), you will get a cluster timer stored in db timer (which can be migrated)

If you declare a timer with @Schedule (..., persistent = false), you will get a node timer that will not be saved in the db timer (which cannot be carried over)

+8
source

You can look at using JMS. For a method that should be executed on one node, use a queue, and for those that should be executed on all nodes, use a topic.

0
source

Source: https://habr.com/ru/post/919234/


All Articles