2 Replies Latest reply on Oct 1, 2002 5:34 AM by Ignacio de Cordoba

    How many stateless session beans are created?

    Ignacio de Cordoba Novice

      Hi there,
      I am figuring out how would be the best method to create a "online user list" bean with EJBs. Actually I have it in the client side (JavaBeans + JSP) but I wan't to take care of this inside the EJB container.
      I have two options... making a OnlineUserBean Entity Bean, but that would mean forcing the container to work with the JDBC just for maintainit the onlineuser list (which needs no persistence as if the server is shut down all online users go obviously offline).
      The second way is using a stateless session bean, but I am not sure if I can create this bean and putting in it a private Hashtable to take care of online users. Does the container just create one instance of stateless session beans or several?
      If it creates several I can't use this method.
      Any comments?
      Any other ideas?


        • 1. Re: How many stateless session beans are created?
          Joel Vogt Master

          you'll get one per session. How about letting each user have a message bean that subscribes to a user list publisher? As each user logs in, send a jms message to the topic which will then be received and added to each user's list. (and same with logoff).

          • 2. Re: How many stateless session beans are created?
            Ignacio de Cordoba Novice

            Thanks for your reply,
            Even though I have been developing J2EE Entity and Session beans for a while, I am pretty new to Message Driven Beans.
            In your example, I don't get to understand where is actually the online user list stored.
            As I have understood MDBeans, as you propose it, when a user logs in, he will only receive messages sent by users that log in after him, is that right? This way, a user will have only the list of online users logged after him.

            I need to store the user list somewhere... but after reading the tutorial on Message Driven Beans, they seem to be similar to Stateles Session beans: You can have just one or several instances of the bean, depending on the container needs.

            Anyway, in my application, only a special user, with admin privileges, is interested in that online user list.

            Before changing to J2EE, my application was just a Web application (.war). The online user list was kept as a context attribute. every time a User object was binded to the session, he looked for the context attribute "onlineuserlist", and invoked a online(me) method. The same when this object was unbinded (the user went offline).
            I'd like to find a way to migrate this to the container, but I don't find a similar concept in J2EE to "Context attributes" of WEB applications.

            Thanks for any help/ideas,