Skip to main content
unmodifiableSet -> synchronizedSet
Source Link
JvR
  • 2.8k
  • 12
  • 25

There are several thread safety issues :

  1. if size(), remove() and removeAll() need to wait(), they will throw an IllegalMonitorStateException since they do not hold the lock on this at the time they call wait();
  2. for that same reason, they may see stale values for isUpdating
  3. if size() would be interrupted while waiting (supposing that gets fixed) its return statement would result in a NullPointerException.
  4. while many threads may be waiting, only one will be notified when isUpdating is set to false again, since you call notify() instead of notifyAll()
  5. operations such as contains() and isEmpty() may see stale values since they are not properly synchronized.
  6. when interrupted all overridden methods violate the Set contract.
  7. the interrupted flag is cleared upon interruption since the InterruptedException is caught and the state is not set to interrupted again.
  8. not strictly a problem, but you synchronize on this. This means third party code locking on your Set will influence its behavior. It is preferrable to lock on a private Object.

I'm not sure what you mean exactly by 'proper size'.

Also, I think that if you properly implement this, you'll basically end up with the same behavior as what you'd get from Collections.unmodifiableSetsynchronizedSet(new LinkedHashSet())

There are several thread safety issues :

  1. if size(), remove() and removeAll() need to wait(), they will throw an IllegalMonitorStateException since they do not hold the lock on this at the time they call wait();
  2. for that same reason, they may see stale values for isUpdating
  3. if size() would be interrupted while waiting (supposing that gets fixed) its return statement would result in a NullPointerException.
  4. while many threads may be waiting, only one will be notified when isUpdating is set to false again, since you call notify() instead of notifyAll()
  5. operations such as contains() and isEmpty() may see stale values since they are not properly synchronized.
  6. when interrupted all overridden methods violate the Set contract.
  7. the interrupted flag is cleared upon interruption since the InterruptedException is caught and the state is not set to interrupted again.
  8. not strictly a problem, but you synchronize on this. This means third party code locking on your Set will influence its behavior. It is preferrable to lock on a private Object.

I'm not sure what you mean exactly by 'proper size'.

Also, I think that if you properly implement this, you'll basically end up with the same behavior as what you'd get from Collections.unmodifiableSet(new LinkedHashSet())

There are several thread safety issues :

  1. if size(), remove() and removeAll() need to wait(), they will throw an IllegalMonitorStateException since they do not hold the lock on this at the time they call wait();
  2. for that same reason, they may see stale values for isUpdating
  3. if size() would be interrupted while waiting (supposing that gets fixed) its return statement would result in a NullPointerException.
  4. while many threads may be waiting, only one will be notified when isUpdating is set to false again, since you call notify() instead of notifyAll()
  5. operations such as contains() and isEmpty() may see stale values since they are not properly synchronized.
  6. when interrupted all overridden methods violate the Set contract.
  7. the interrupted flag is cleared upon interruption since the InterruptedException is caught and the state is not set to interrupted again.
  8. not strictly a problem, but you synchronize on this. This means third party code locking on your Set will influence its behavior. It is preferrable to lock on a private Object.

I'm not sure what you mean exactly by 'proper size'.

Also, I think that if you properly implement this, you'll basically end up with the same behavior as what you'd get from Collections.synchronizedSet(new LinkedHashSet())

added 45 characters in body
Source Link
bowmore
  • 5.4k
  • 1
  • 20
  • 23

There are several thread safety issues :

  1. if size(), remove() and removeAll() need to wait(), they will throw an IllegalMonitorStateException since they do not hold the lock on this at the time they call wait();
  2. for that same reason, they may see stale values for isUpdating
  3. if size() would be interrupted while waiting (supposing that gets fixed) its return statement would result in a NullPointerException.
  4. while many threads may be waiting, only one will be notified when isUpdating is set to false again, since you call notify() instead of notifyAll()
  5. operations such as contains() and isEmpty() may see stale values since they are not properly synchronized.
  6. when interrupted all overridden methods violate the Set contract.
  7. the interrupted flag is cleared upon interruption since the InterruptedException is caught and the state is not set to interrupted again.
  8. not strictly a problem, but you synchronize on this. This means third party code locking on your Set will influence its behavior. It is preferrable to lock on a private Object.

I'm not sure what you mean exactly by 'proper size'.

Also, I think that if you properly implement this, you'll basically end up with the same behavior as what you'd get from Collections.unmodifiableSet(new LinkedHashSet())

There are several thread safety issues :

  1. if size(), remove() and removeAll() need to wait(), they will throw an IllegalMonitorStateException since they do not hold the lock on this at the time they call wait();
  2. for that same reason, they may see stale values for isUpdating
  3. if size() would be interrupted while waiting (supposing that gets fixed) its return statement would result in a NullPointerException.
  4. while many threads may be waiting, only one will be notified when isUpdating is set to false again, since you call notify() instead of notifyAll()
  5. operations such as contains() and isEmpty() may see stale values since they are not properly synchronized.
  6. when interrupted all overridden methods violate the Set contract.
  7. the interrupted flag is cleared upon interruption since the InterruptedException is caught and the state is not set to interrupted again.
  8. not strictly a problem, but you synchronize on this. This means third party code locking on your Set will influence its behavior.

I'm not sure what you mean exactly by 'proper size'.

Also, I think that if you properly implement this, you'll basically end up with the same behavior as what you'd get from Collections.unmodifiableSet(new LinkedHashSet())

There are several thread safety issues :

  1. if size(), remove() and removeAll() need to wait(), they will throw an IllegalMonitorStateException since they do not hold the lock on this at the time they call wait();
  2. for that same reason, they may see stale values for isUpdating
  3. if size() would be interrupted while waiting (supposing that gets fixed) its return statement would result in a NullPointerException.
  4. while many threads may be waiting, only one will be notified when isUpdating is set to false again, since you call notify() instead of notifyAll()
  5. operations such as contains() and isEmpty() may see stale values since they are not properly synchronized.
  6. when interrupted all overridden methods violate the Set contract.
  7. the interrupted flag is cleared upon interruption since the InterruptedException is caught and the state is not set to interrupted again.
  8. not strictly a problem, but you synchronize on this. This means third party code locking on your Set will influence its behavior. It is preferrable to lock on a private Object.

I'm not sure what you mean exactly by 'proper size'.

Also, I think that if you properly implement this, you'll basically end up with the same behavior as what you'd get from Collections.unmodifiableSet(new LinkedHashSet())

There are several thread safety issues :

  • if size(), remove() and removeAll() need to wait(), they will throw an IllegalMonitorStateException since they do not hold the lock on this at the time they call wait();
  • for that same reason, they may see stale values for isUpdating
  • if size() would be interrupted while waiting (supposing that gets fixed) its return statement would result in a NullPointerException.
  • while many threads may be waiting, only one will be notified when isUpdating is set to false again, since you call notify() instead of notifyAll()
  • operations such as contains() and isEmpty() may see stale values since they are not properly synchronized.
  • when interrupted all overridden methods violate the Set contract.
  • the interrupted flag is cleared upon interruption since the InterruptedException is caught and the state is not set to interrupted again.
  • not strictly a problem, but you synchronize on this. This means third party code locking on your Set will influence its behavior.
  1. if size(), remove() and removeAll() need to wait(), they will throw an IllegalMonitorStateException since they do not hold the lock on this at the time they call wait();
  2. for that same reason, they may see stale values for isUpdating
  3. if size() would be interrupted while waiting (supposing that gets fixed) its return statement would result in a NullPointerException.
  4. while many threads may be waiting, only one will be notified when isUpdating is set to false again, since you call notify() instead of notifyAll()
  5. operations such as contains() and isEmpty() may see stale values since they are not properly synchronized.
  6. when interrupted all overridden methods violate the Set contract.
  7. the interrupted flag is cleared upon interruption since the InterruptedException is caught and the state is not set to interrupted again.
  8. not strictly a problem, but you synchronize on this. This means third party code locking on your Set will influence its behavior.

I'm not sure what you mean exactly by 'proper size'.

Also, I think that if you properly implement this, you'll basically end up with the same behavior as what you'd get from Collections.unmodifiableSet(new LinkedHashSet())

There are several thread safety issues :

  • if size(), remove() and removeAll() need to wait(), they will throw an IllegalMonitorStateException since they do not hold the lock on this at the time they call wait();
  • for that same reason, they may see stale values for isUpdating
  • if size() would be interrupted while waiting (supposing that gets fixed) its return statement would result in a NullPointerException.
  • while many threads may be waiting, only one will be notified when isUpdating is set to false again, since you call notify() instead of notifyAll()
  • operations such as contains() and isEmpty() may see stale values since they are not properly synchronized.
  • when interrupted all overridden methods violate the Set contract.
  • the interrupted flag is cleared upon interruption since the InterruptedException is caught and the state is not set to interrupted again.
  • not strictly a problem, but you synchronize on this. This means third party code locking on your Set will influence its behavior.

I'm not sure what you mean exactly by 'proper size'.

Also, I think that if you properly implement this, you'll basically end up with the same behavior as what you'd get from Collections.unmodifiableSet(new LinkedHashSet())

There are several thread safety issues :

  1. if size(), remove() and removeAll() need to wait(), they will throw an IllegalMonitorStateException since they do not hold the lock on this at the time they call wait();
  2. for that same reason, they may see stale values for isUpdating
  3. if size() would be interrupted while waiting (supposing that gets fixed) its return statement would result in a NullPointerException.
  4. while many threads may be waiting, only one will be notified when isUpdating is set to false again, since you call notify() instead of notifyAll()
  5. operations such as contains() and isEmpty() may see stale values since they are not properly synchronized.
  6. when interrupted all overridden methods violate the Set contract.
  7. the interrupted flag is cleared upon interruption since the InterruptedException is caught and the state is not set to interrupted again.
  8. not strictly a problem, but you synchronize on this. This means third party code locking on your Set will influence its behavior.

I'm not sure what you mean exactly by 'proper size'.

Also, I think that if you properly implement this, you'll basically end up with the same behavior as what you'd get from Collections.unmodifiableSet(new LinkedHashSet())

Source Link
bowmore
  • 5.4k
  • 1
  • 20
  • 23
Loading