0

I have a singleton EJB bean with a timed method that saves statistics to the database once every minute. The bean holds statistics individually on each cluster node, so it is important that it saves it on each node too.

My concern is that since the EJB Timer service is sharing a database, it will only run the save-method on one of the cluster nodes and not all of them. It would mean that not all of the statistics are saved to the database. The docs, http://docs.oracle.com/cd/E18930_01/html/821-2418/beahw.html, does not seem to mention anything.

Anyone know how it works?

Bjørn Stenfeldt
  • 1,432
  • 1
  • 18
  • 25
  • I think you could use @Singleton+@Startup as they are per node. Then create the timers pragmatically in the beans @PostConstruct – Aksel Willgert May 14 '13 at 08:37
  • Right now my bean has `@Singleton`, while my save method has `@PreDestroy + @Schedule(minute = "*/1", hour = "*")`. I am not sure what you mean, but my concern is that the save method only run each minut on one cluster node and not on each and all of the nodes. – Bjørn Stenfeldt May 14 '13 at 08:56
  • I found the answer here: http://stackoverflow.com/questions/14472689/glassfish-clustering-ejb-lookup – Bjørn Stenfeldt May 14 '13 at 12:26
  • how does that answer the question? as i understand it only explains why the method is only invoked on one node. – Aksel Willgert May 14 '13 at 16:00
  • I just wanted to know if the method was going to be invoked on one node or each node. And maybe if it was possible to change that behavior, but that was secondary. – Bjørn Stenfeldt May 15 '13 at 06:37

1 Answers1

1

If you declare the timer with @Schedule(..., persistent=true), you will get a cluster timer stored in the timer db (which can be migrated), so it will run in only one node.

If you declare the timer with @Schedule(..., persistent=false), you will get a node timer not stored in the timer db (which can't be migrated), so it will be invoked on each node.

Camilla
  • 489
  • 5
  • 14