1 2 Previous Next 24 Replies Latest reply on May 12, 2003 1:00 PM by jk.mkiii Go to original post
      • 15. Re: Stateful SB removed under Stateles :(
        jk.mkiii

        Thanks for idea, but unfortunately I don't see how that would help unless I start everything from scratch.

        Stateful bean is access to our internal repository and I really don't think our partners would be that happy if we say that we scratch our old system and get back to them after year.

        There is no escaping having that stateful session bean, unless I find way to change it (and every other stateful bean under it) to stateless beans and get input parameters some different way because in current setup they will always be same.

        I know that in code I could fix problem by always looking up underlying resources in stateless bean, but that sounds little silly.

        I was hoping that it would be possible to clean up stateless session beans after while, so when they are inactive for long enough references to stateful beans are removed before stateful beans are silently removed from disk.

        From book I mentioned I understood that max-bean-life would do exactly this even for stateless beans.

        My second choise is that I try to set stateful beans so that they are never removed from disk. Does anyone know how to do this? Can I expand standard configuration and set remove time to 0 or perhaps negative value, or do I have to setup full configuration?

        But I would think first option would be better choise. So if someone would know what is wrong in my jboss.xml it would be great. Oh, and that is only jboss.xml I have because other beans just use standard configuration (which I have not modified in any way).

        • 16. Re: Stateful SB removed under Stateles :(

          I repeat the bean ageing does not apply to
          stateless only to stateful.

          Stateless beans do not have a cache, all
          stateless beans are equivalent in a pool.

          Storing a reference to a stateful bean in a
          stateless bean breaks that contract unless they
          all reference the same stateful bean instance.
          But this then breaks the single threading
          requirement of stateful beans unless you configure
          your stateless pool to have a strict size of 1.

          Regards,
          Adrian

          • 17. Re: Stateful SB removed under Stateles :(
            jk.mkiii

            So it seems that there is error in this book I am using.

            But I do not see that aging old unused bean instances and having all beans equivalent are two exclusive things.

            How does having stateful bean under stateless bean make those stateless beans not equal? I should not matter which stateless bean is used, but it does not mean that they all have to use exact same objects.

            If two stateless beans use different stateful beans to load data with exact same selection rule you get exact same data, even when stateful beans are not same. These stateful beans in our system are used to load and if possible cache data.

            • 18. Re: Stateful SB removed under Stateles :(
              jonlee

              Stateless beans of the same type are kept in a single pool. They are stateless, meaning that if I grabbed one and used that bean, it would react no differently to doing the same with another one I randomly grabbed from the pool. As I finish with a stateless session bean, it gets released back to the pool. Next time I grab another bean from this pool, it might be the same bean or it might be another.

              Stateless session beans are only destroyed if you shut down the container, or as a result of the pool shrinking as demand shrinks. You often do not want your pool to shrink to zero - it is costly to create a new bean, so for much the same reason that you have connection pools because connections are costly to create so we have stateless session beans. We want enough stateless session beans pre-created and available in the pool to service standard load for the application.

              Every request for a stateless session bean does not necessarily mean that a stateless session bean is created. The container decides whether there is a bean available for the request, and if there is not, and the maximum number of those beans allowed has not been reached, it will create one. Otherwise, the container will just give you one of the beans already existing in the pool, because no bean is different to another.

              The rate of decay is not required to be defined in containers for a stateless session pool, like the rate of decay for a connection pool - e.g How quickly the pool shrinks. Nor are there any definitions for the basis of disposal - it could be LRU, it could be round-robin; the algorithm chosen may be the one most resource efficient for the architecture.

              You have modified things. Each stateless bean is different as it is attached to a different or unique stateful session bean. This one to one binding makes each stateless session bean unique in terms of the method use - it is dependent on an underlying service that is not guaranteed to exist for the lifetime of the container. Essentially, you have violated the non-uniqueness criteria for the use of stateless session beans with this dependency.

              This is your test for a stateless session bean - if I randomly choose a stateless session bean from the pool and use a method of that bean, can I be guaranteed, without any provisos, of receiving the same result if I then randomly grab another bean from the pool and use the same method with the same method input parameter values?

              • 19. Re: Stateful SB removed under Stateles :(
                jk.mkiii

                Yes. Any stateless bean will get exactly same data.

                I know each call to stateless bean will randomly pick one of them.

                • 20. Re: Stateful SB removed under Stateles :(
                  jonlee

                  No it won't because you can get the case where the underlying stateful session bean has disappeared. Therefore, it is not without proviso that your stateless session beans will return the same data, regardless of the instance, for the lifetime of the stateless session bean pool (and the container which runs it).

                  • 21. Re: Stateful SB removed under Stateles :(
                    jk.mkiii

                    All stateless beans will return exactly same data, unless bean throws exception because stateful instance is removed under it. But if stateless bean in this case would create new stateful bean instance it would get exactly same data.

                    So only case where result would be different is where stateless bean notices error because server has removed bean instance under it. If I would create new stateful instances for every method call it would work exactly same way as it would work if those stateful beans were not removed due to inactivity. If I catch exception (if possible) that is thrown when JBoss notices stateful bean can not be activated and create new stateful bean everything will work exactly as planned, but little slower.

                    So those stateful bean instances do not matter. I could open and close them every time, it just slows things.

                    Every instance of these stateful beans created with same selection rule will always return exactly same data, only difference might be in speed.

                    I am 100% sure that all my stateless beans will return exactly same data. All I want to fix is that those stateful beans instances are not removed under it.


                    • 22. Re: Stateful SB removed under Stateles :(
                      jonlee

                      Maybe we aren't being clear about this. So let us forget about the mechanics. Instead let us get down to specific cases.

                      You have a stateless session bean that connects to the stateful session bean. Nothing else can access that stateful session bean to keep it active except the stateless session bean. You have a hit or miss chance of accessing a session bean connected to a particular stateful session bean to stop that stateful session bean from being passivated, much less destroyed.

                      Therefore, for your design you will need to take care of the exception in your stateless session bean and create a new stateful session bean if the old one is destroyed.

                      Or make the stateful session live for ever. Except this is a problem if the stateless session bean is destroyed such as when the container is shut down or the number of stateless session beans shrink to the pool minimum. This is because you will have orphaned stateful session beans.

                      Those are the options open to you under your current design guidelines.

                      • 23. Re: Stateful SB removed under Stateles :(

                        Why do you need a stateful bean if they are
                        all equivalent?
                        The idea of stateful beans is to store client state.

                        NOTE: Stateless beans means they are stateless
                        with respect to the client not internally.
                        A stateless bean can store state that is only
                        used for the internal processing of requests.

                        To answer your specific question:

                        These paremeters control the removal
                        <remover-period>1800</remover-period>
                        <max-bean-life>1800</max-bean-life>

                        These control the passivation (writing to disk
                        when unused to free memory)
                        <overager-period>300</overager-period>
                        <max-bean-age>600</max-bean-age>

                        As you say, a runtime or remote exception
                        will also remove the stateful bean.

                        Regards,
                        Adrian

                        • 24. Re: Stateful SB removed under Stateles :(
                          jk.mkiii

                          There are couple reasons why I use those stateful beans under stateless beans even when those are always same.

                          1) Stateful beans are old implementation that we already have. Stateless beans are new addition.

                          2) We have 2 level selection on data. 1st on creation of LinkSet (our stateful bean) we give one selection and when really looking up something selection is limited inside this original selection. If changed things to stateless beans would have to get this selection rule from somewhere and we have no format that could be put in deployment description.

                          3) We will most likely have connection that will soon really use LinkSet way it was meant to. So that it needs to be stateful so don't want to break things too much..

                          I will have to look if I could modify those beans so that they could be used as stateless beans also if original selection is always same. Perhaps we should put selection rule into JNDI when server is started and look it up from there.




                          1 2 Previous Next