6 Replies Latest reply on Sep 14, 2004 10:26 AM by frito

    synchronizing a session bean

    twutort

      Hello,

      I'm having an issue with some legacy code I had to take over. There is a session bean that has a singleton class. In that singleton class there is a method where a socket is opened up and some data is sent and received. Problem is when two users use the session beans to send data on the socket it there are problems with the order in which the data is recieved. I know you can't use synchronized within a session bean. Is there anyway to synchronize a method in a session bean through jboss so that each call to this method completes before the next session bean executes it?

      Thanks,
      twutort

        • 1. Re: synchronizing a session bean
          darranl

          You could configure the session bean so that it is in a pool with a strict maximum size of 1.

          That way you will never get more than one client calling the session bean.

          If you look at the 'Free Docos' to the right you should get access to the administrators and developers guide which describes configuring the container.

          • 2. Re: synchronizing a session bean
            twutort

            Thanks. Can this be done for one particular session bean and not the others?

            • 3. Re: synchronizing a session bean
              darranl

              Yes this can be done for just one session bean.

              In your JBoss.xml you define the new container configuration probably by extending an existing config. For the bean concerned you specify that it should use the new config instead of the existing config.

              • 4. Re: synchronizing a session bean
                twutort

                Thanks. Can you synchronize within a class that the session bean uses? For example, the session bean calls class B. Is it possible to do the synch within the class B and not inside the session bean?

                • 5. Re: synchronizing a session bean
                  darranl

                  You should probably wrap the class with it's own session bean if that is what you are trying to achieve.

                  • 6. Re: synchronizing a session bean
                    frito

                    @twutort:
                    reading the words "session bean", "synchronized", "socket" and "singleton" in one posting is scaring me a bit ;-)
                    Since the singleton (and therefore the synchronisation) depends on the deployment (a singleton is a singleton for a specific ClassLoader) i won't rely on this.
                    I recommend using a real singleton with synchronisation by implementing a MBean which does the socket things. The session bean calls the MBean and you don't have to deal with "a single instance session bean"