존재하지 않지만이 구문과 비슷한 것을 찾고 있습니다.Java에서 객체 동기화
메서드를 컬렉션에 적용하고 메서드 수명 동안 컬렉션이 엉망이되지 않도록해야합니다.
그래서 같이 수 :
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
}
대신, 나는이 될 것이라고 할 수있는 유일한 방법은 두려워 :
private void doSomethingWithTheCollectionX(List<?> collectionX) {
synchronized(collectionX) {
// do something with collection x here
}
}
이 가장 좋은 방법은 그것을 할인가요?
, 여기에 유일한 차이점은 들여 쓰기 수준이다. – Radiodef