私はこの構文に似た何かを探していますが、それは存在しません。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