The method is list()not synchronized.
Thus, any call (even synchronized) to the instance Propertiesduring the call list()can violate the state of the object and lead to an exception or broken logic.
Assume that instead of using an intermediate instance of Properties, we iterating directly onto the instance, Propertiesit will not be thread safe
, : Thread A, list() Thread B, remove() Properties.
list() .
, list():
String key = e.nextElement();
String val = (String)h.get(key);
if (val.length() > 40) {
, A :
String key = e.nextElement();
B instance.remove() , , A
, A , :
String val = (String)h.get(key);
.
, val null:
if (val.length() > 40) {