Meaningless Drivel is fun!*
The moose likes EJB and other Java EE Technologies and the fly likes Ejb cache with singelton implementation Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "Ejb cache with singelton implementation" Watch "Ejb cache with singelton implementation" New topic
Author

Ejb cache with singelton implementation

arik salv
Greenhorn

Joined: Mar 24, 2012
Posts: 1
I would appreciate your advice about an issue I have.

I'm working with jboss, EJB 3.1 environment.

each time the user entering a specific screen, it should be a trigger for creating a tree data type which based on a data that saved on the database. this tree calculation can take some time, and it's can be heavy on performance.

the following requests are sent from UI :

  • 1. refreshTree - a trigger for building the tree
    2. isTreeReady - indicating whether the tree is ready to use, and called every x amount of time
    3. getTree - return the tree.


  • when building this I should take into consideration that multiple users can try to perform each one of those actions simultaneously. it's also true that 2 users share the same tree if any refresh hasn't been done.

    I've thought about implementing it as a cache as follow :



    the issue I have with that is that there can be a scenario in which :

    first user refreshing the tree - and the tree is built.
    then second user start to build the tree, and initialize the isReady flag to false, before the first user has noticed about the tree calculation - in this case the first user will need to wait to the calculation to be completed (even though he could have use the tree).

    I'm trying to think a bout using a read lock in some way (instead of the isTreeReady flag), but I can't think about any that will fit my needs.

    do you have an idea what can I do?

    thanks.
     
    wood burning stoves
     
    subject: Ejb cache with singelton implementation