In a clustered JEE6 environment (Glassfish 3.1.2), a @Singleton bean is/can be created on every cluster node. If this Singleton Bean registers a programmatic timer on its @PostConstruct - how often is the @Timeout method executed? -- on only one of that singletons (per tick), or once (per tick) for each Singeton that registered that a timer?
Below the code is an example what this question mean to this code.
@Singleton
public class CachedService {
@Resource
private TimerService timerService;
private static final long CACHE_TIMEOUT_DURATION_MS = 60 * 60 * 1000;
@PostConstruct
void initResetTimer() {
this.timerService.createIntervalTimer(CACHE_TIMEOUT_DURATION_MS,
CACHE_TIMEOUT_DURATION_MS,
new TimerConfig("current user cache timeout", false));
}
@Timeout
public void executeResetTimer() {
this.clearCache();
}
}
Example: The application runs on 3 nodes in a cluster. Assume the Singleton is instantiated on every node, so the initResetTimer is done 3 times in total (once per node). Then the question is: is the cache cleared (executeResetTimer is invoked) on all nodes once per hour or not?
(I know that the timer ticks not at the same time on all nodes, because the Singleton is instantiated at different times, but this is not the problem/question.)