3 Replies Latest reply on Jan 11, 2008 11:00 AM by Dimitris Andreadis

    How to have multiple instances of an MBean

    Praveen kumar B Newbie

      I've deployed an mbean in jboss container, and the container is calling the create, start, methods of the mbean.
      Now i need to create multiple instances of an mbean , one per request from the client. The mbean objectName remains the same.
      Can any one tell me how to achieve this?

        • 1. Re: How to have multiple instances of an MBean
          Dimitris Andreadis Master

          The mbean name must be unique, so you'll have to add something in the name for uniqueness, e.g. mydomain:name=mymbean,id=123

          Also note that you can't have more than a couple of thousand mbeans, it won't scale.

          • 2. Re: How to have multiple instances of an MBean
            Praveen kumar B Newbie

            Thanks, this information really helps. As a new-bie in this field, i'd like to ask a question related to concurrency offered by the container to handle multiple requests on same dynamic mbean. For example, say on a request a dynamic mbean queries a resource and populates it's attribute, done using MBeanInfo which is built dynamically. But say in a case where two requests come to a single instance of mbean and the resources the mbean is going to query are different and hence the attributes are different, how can this case be handled?
            Essentially can an mbean have multiple MBeanInfo at the same time?

            • 3. Re: How to have multiple instances of an MBean
              Dimitris Andreadis Master

              By design mbeans must handle their own concurrency, as many threads can be accessing them.

              Dynamic mbeans can alter their mbean interface dynamically, e.g. now they report 3 attributes and 2 operation, then next moment 5 attributes and 4 operations, although this is not very common.

              Conceptually, the mbean would report a single MBeanInfo, at any given point in time, in practise, you can alter the reported mbeaninfo even for concurrent requests, but this is certainly a sick thing to do.

              Dynamic mbeans are really meant for adapting their interface to a particular backend/resource upon creation, plus they are supposed to be a little faster (no reflective calls), but harder to code. They are not meant for changing their interface every millisecond.

              I think you should start the other way round. What you want to do?