synchronized various methods to avoid deadlock

one of our apps was stuck in a deadlock in ResourceProperties.size(),
see excerpt of the stack trace below. this fix synchronizes various overriding
methods since they are synchronized in Hashtable as well.

removed superfluous toString method too.

```
"app-230":
        at java.util.Hashtable.size(Hashtable.java:206)
        - waiting to lock <0xa13f8548> (a helma.util.ResourceProperties)
        at helma.util.ResourceProperties.size(ResourceProperties.java:529)
        at java.util.Hashtable.equals(Hashtable.java:742)
        - locked <0xa1065708> (a helma.util.ResourceProperties)
        at helma.objectmodel.db.DbSource.equals(DbSource.java:292)
        ...
"app-439":
        at java.util.Hashtable.size(Hashtable.java:206)
        - waiting to lock <0xa1065708> (a helma.util.ResourceProperties)
        at helma.util.ResourceProperties.size(ResourceProperties.java:529)
        at java.util.Hashtable.equals(Hashtable.java:742)
        - locked <0xa13f8548> (a helma.util.ResourceProperties)
        at helma.objectmodel.db.DbSource.equals(DbSource.java:292)
        ...
```
This commit is contained in:
Robert Gaggl 2013-03-06 10:09:50 +01:00
parent f808a7b7f7
commit fd0b77bc11

View file

@ -303,7 +303,7 @@ public class ResourceProperties extends Properties {
* @param value value to look for
* @return true if the value is found in the value list
*/
public boolean contains(Object value) {
public synchronized boolean contains(Object value) {
if ((System.currentTimeMillis() - lastCheck) > CACHE_TIME) {
update();
}
@ -315,7 +315,7 @@ public class ResourceProperties extends Properties {
* @param key key to look for
* @return true if the key is found in the key list
*/
public boolean containsKey(Object key) {
public synchronized boolean containsKey(Object key) {
if ((System.currentTimeMillis() - lastCheck) > CACHE_TIME) {
update();
}
@ -330,7 +330,7 @@ public class ResourceProperties extends Properties {
* Returns an enumeration of all values
* @return values enumeration
*/
public Enumeration elements() {
public synchronized Enumeration elements() {
if ((System.currentTimeMillis() - lastCheck) > CACHE_TIME) {
update();
}
@ -342,7 +342,7 @@ public class ResourceProperties extends Properties {
* @param key key to use for fetching the value
* @return value belonging to the given key
*/
public Object get(Object key) {
public synchronized Object get(Object key) {
if ((System.currentTimeMillis() - lastCheck) > CACHE_TIME) {
update();
}
@ -438,7 +438,7 @@ public class ResourceProperties extends Properties {
* Checks wether the properties list is empty
* @return true if the properties list is empty
*/
public boolean isEmpty() {
public synchronized boolean isEmpty() {
if ((System.currentTimeMillis() - lastCheck) > CACHE_TIME) {
update();
}
@ -457,7 +457,7 @@ public class ResourceProperties extends Properties {
* Returns an enumeration of all keys
* @return keys enumeration
*/
public Enumeration keys() {
public synchronized Enumeration keys() {
if ((System.currentTimeMillis() - lastCheck) > CACHE_TIME) {
update();
}
@ -522,7 +522,7 @@ public class ResourceProperties extends Properties {
* Returns the number of peroperties in the list
* @return number of properties
*/
public int size() {
public synchronized int size() {
if ((System.currentTimeMillis() - lastCheck) > CACHE_TIME) {
update();
}
@ -532,17 +532,9 @@ public class ResourceProperties extends Properties {
/**
* Overwrite clear() to also empty the key map.
*/
public void clear() {
public synchronized void clear() {
keyMap.clear();
super.clear();
}
/**
* Returns a string-representation of the class
* @return string
*/
public String toString() {
return super.toString();
}
}