3 Replies Latest reply on Apr 15, 2011 1:33 AM by jaikiran

    JBoss @Service vs. EJB3.1 @Singleton

    david_b

      Hi all,

       

      I'm wondering what the practical differences are between a JBoss @Service bean and the new @Singleton beans in EJB3.1? I'm developing for JBoss AS 6, so both options are available.

       

      My current code base uses service beans for various tasks e.g. caching configuration parameters read from a database. It seems like Singleton beans were introduced to address precisely this type of problem.

       

      I'm at a point in the project where I'm refactoring the service beans, so I'm wondering if it's feasible to change them to the standards compliant Singleton beans. Are there any subtle differences that I need to know about?

       

      The only potential issue I can see is that they need to operate in a clustered environment i.e. singleton across the cluster, replicate state across the cluster. I've achieved this with service beans by deploying them as a high-availability service. I haven't seen much information on deploying singleton beans in this way but I assume the process is similar.

       

      Any insight would be appreciated.

       

      David

        • 1. JBoss @Service vs. EJB3.1 @Singleton
          jaikiran

          Starting JBoss AS6, the JBoss specific @Service has been deprecated. It's recommended that you start using @Singleton.

           

          The only additional advantage that the JBoss specific @Service beans provided was that you could register a MBean (by using @Management) for the @Service bean. That isn't supported for @Singleton.

          • 2. JBoss @Service vs. EJB3.1 @Singleton
            david_b

            Thanks, in that case I'll definitely be switching over.

             

            The services are being registered as MBeans using @Management, but only to use start/create/stop/destroy. These can be replaced with @PostConstruct/@PreDestroy etc.

            • 3. JBoss @Service vs. EJB3.1 @Singleton
              jaikiran

              david_b wrote:

               

               

               

              The services are being registered as MBeans using @Management, but only to use start/create/stop/destroy. These can be replaced with @PostConstruct/@PreDestroy etc.

              That's correct. Also you can add a @Startup to the @Singleton to make it behave like @Service (i.e. create an instance on server/deployment start).