I am looking for something similar to this syntax, even if it does not exist.
I want to have a method action in the collection and for the lifetime of the method so that the collection is not confused.
So it might look like this:
private void synchronized(collectionX) doSomethingWithCollectionX() { // do something with collection x here, method acquires and releases lock on // collectionX automatically before and after the method is called }
but instead, I'm afraid the only way to do this would be:
private void doSomethingWithTheCollectionX(List<?> collectionX) { synchronized(collectionX) {
Is this the best way to do this?
source share