F
flythefriendlyskies
Hi,
we have a problem with our application standing still for up to several
minutes in a method that looks like the method get() below. The most
obvious reason would be that there is one thread locking on 'value' and
all other threads simply wait on the first one. The issue is: With all
traces we have so far we still have no evidence for a thread really
being inside the synchronized block for quite a while.
Most of the time everything runs well, 99% of the application runtime
everything is fine, but the pause times (up to three minutes within a
web app) are simply too high to leave the system as it is right now.
So, here is the code (written a long time ago...):
Firstly, it reminds of the double-checked locking problem, but I don't
think that this is an issue here. Secondly, within the synchronization
block there is a new assignment to the variable that is used for
locking. I've never seen this pattern before. Are you aware of any
potential problems here? From the code, do you think there are other
reasons why threads would spend >30 seconds in the get() method?
We run on IBM JVM 1.4.2
public Object get() {
Object value = getInternal();
if (value instanceof String) {
return value;
}
synchronized (value) {
value = dcl.get(KEY);
if (value instanceof String) {
return value;
}
dcl.put(KEY, VALUE);
}
return VALUE;
}
public Object getInternal() {
Object result = dcl.get(KEY);
if (result == null) {
result = new Object();
dcl.put(KEY, result);
}
return result;
}
Thanks for your help,
Michael
we have a problem with our application standing still for up to several
minutes in a method that looks like the method get() below. The most
obvious reason would be that there is one thread locking on 'value' and
all other threads simply wait on the first one. The issue is: With all
traces we have so far we still have no evidence for a thread really
being inside the synchronized block for quite a while.
Most of the time everything runs well, 99% of the application runtime
everything is fine, but the pause times (up to three minutes within a
web app) are simply too high to leave the system as it is right now.
So, here is the code (written a long time ago...):
Firstly, it reminds of the double-checked locking problem, but I don't
think that this is an issue here. Secondly, within the synchronization
block there is a new assignment to the variable that is used for
locking. I've never seen this pattern before. Are you aware of any
potential problems here? From the code, do you think there are other
reasons why threads would spend >30 seconds in the get() method?
We run on IBM JVM 1.4.2
public Object get() {
Object value = getInternal();
if (value instanceof String) {
return value;
}
synchronized (value) {
value = dcl.get(KEY);
if (value instanceof String) {
return value;
}
dcl.put(KEY, VALUE);
}
return VALUE;
}
public Object getInternal() {
Object result = dcl.get(KEY);
if (result == null) {
result = new Object();
dcl.put(KEY, result);
}
return result;
}
Thanks for your help,
Michael