entity beans - using 'sychronized'

Discussion in 'Java' started by timasmith@hotmail.com, Dec 11, 2005.

  1. Guest

    Hi,

    My entity BMP bean has a cache of data, lets call it encapsulated by my
    object 'cache'.

    Every now and then I reload the cache - and want to prevent access
    during that time (several seconds).

    However the rest of time every one can have at it. Here is what I have
    come up with - but I think synchronizing every single read is a little
    over the top. Is there a cheaper 'read only' synchronization option?
    Or a better way to do this without handing the data over to the
    container.

    public class MyEntity {

    private Cache cache = new Cache();

    public loadCache() {
    synchronized (this) {
    cache = getNewCache();
    }
    }

    public String readFromCache() {
    synchronized (this) {
    return cache.getStringFromCache();
    }
    }
    }

    thanks

    Tim
    , Dec 11, 2005
    #1
    1. Advertising

  2. Alan Krueger Guest

    wrote:
    > My entity BMP bean has a cache of data, lets call it encapsulated by my
    > object 'cache'.
    >
    > Every now and then I reload the cache - and want to prevent access
    > during that time (several seconds).
    >
    > However the rest of time every one can have at it. Here is what I have
    > come up with - but I think synchronizing every single read is a little
    > over the top. Is there a cheaper 'read only' synchronization option?
    > Or a better way to do this without handing the data over to the
    > container.


    http://www.jguru.com/faq/view.jsp?EID=35269
    Alan Krueger, Dec 11, 2005
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Kabal
    Replies:
    0
    Views:
    926
    Kabal
    Jul 22, 2003
  2. Zhao
    Replies:
    6
    Views:
    365
    Roedy Green
    Oct 17, 2003
  3. MP
    Replies:
    2
    Views:
    2,579
    John C. Bollinger
    Nov 11, 2003
  4. Torsten Schmeissel
    Replies:
    0
    Views:
    407
    Torsten Schmeissel
    Apr 29, 2005
  5. markla
    Replies:
    1
    Views:
    531
    Steven Cheng
    Oct 6, 2008
Loading...

Share This Page