entity beans - using 'sychronized'

T

timasmith

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
 
A

Alan Krueger

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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,017
Latest member
GreenAcreCBDGummiesReview

Latest Threads

Top