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
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