General J2EE: Sequence blocks in EJB Design Pattern Book

  1. Sequence blocks in EJB Design Pattern Book (2 messages)

    I have a question on the pattern "Sequence Blocks" in the EJB Design Patterns Book by FLoyd Marinescu.

    In the Appendix "Pattern Code Lisintg", on page 236, the Stateless Session Bean "Sequence Session" has an instance variable called "_entries" as a hashtable. In the method getNextNumberInSequence(), the first line tries to get an entry from the hashtable. But there could actually be any number of instances of the bean in the pool and the one assigned for the current method execution may not have been the one assigned for a previous execution. So what is the gaurantee that the same hashtble that was populated by a previous client call is being accessed now. So we might end up having a number of hashtables each with an entry for the same name!!!
  2. Ramesh,

    An AppServer generally pools stateless session bean instances and that is the behavior we rely on.

    If there are a number of hashtable instances (say in a cluster or even in the same VM), each of these instances will hold a reference to the entity bean. But the blocks allocated to each session bean instance (retrieved from the entity bean) would be different [and unique].

    That is the beauty of the Portable Primary Key generator.


    PS: Incidentally, the code & idea is based on one by Borland Enterprise Server's architect :)
  3. Thanks Krish. Yes, the idea behind this pattern is to generate unique keys and the emphasis is not on maintaining contiguity and so the same entity bean could get from different blocks and still be fine.

    Ramesh Nagella