Search code examples
jakarta-eepayara

Payara singleton per cluster implementation


Does EJB have clustering defined I have found clustering the Stateless or Statefull beans are platform specific for ex. Jboss has @Clustered annotation but in Payara ? I have the same application on multiple machines and I would like to perform a leader election or a kind of singletion call per whole cluster


Solution

  • The latest release (from 182) of Payara Server and Payara Micro has the ability to use clustered singletons, as described in this blog post: https://blog.payara.fish/introduction-to-clustered-singleton

    You just need to use fish.payara.cluster.Clustered (and make sure the bean is serializable) as the blog explains:

    import fish.payara.cluster.Clustered;
    import javax.ejb.Singleton;
    import javax.enterprise.context.ApplicationScoped;
    
    @Clustered @Singleton
    public class MyClusteredSingletonEJB implements Serializable { /* ... */ }
    
    @Clustered @ApplicationScoped
    public class MyClusteredSingletonCDI implements Serializable { /* ... */ }