public final class JvmGlobalLocks extends Object
String foo; synchronized (foo.intern()) { // ... }
As such this is an extremely bad idea, as it does not make it clear what the locking domain is and what code is actually participating on it. Until we can get proper locking in place, the above should be replaced with:
String foo; final ReentrantLock = JvmGlobalLocks.getLockForString(foo); lock.lock(); try { // ... } finally { lock.unlock(); }
Once all call sites are identified, their use of Strings should be replaced by domain-specific lock identifiers,
so that it is obvious which places actually synchronize on a particular identifier. getLockFor(Identifier)
and getLockFor(Identifiable)
provide this functionality.
Finally, users of this class should look to downgrade from JVM-global to either an explicit locking service, or to fine-grained locks contained within the component instantiation -- thus rendering this class completely unneeded.
Modifier and Type | Method and Description |
---|---|
static @NonNull ReentrantLock |
getLockFor(org.opendaylight.yangtools.yang.binding.Identifiable<?> resource)
Return a JVM-global
ReentrantLock for a particular name. |
static @NonNull ReentrantLock |
getLockFor(org.opendaylight.yangtools.yang.binding.Identifier<?> identifier)
Return a JVM-global
ReentrantLock for an identifier. |
static @NonNull ReentrantLock |
getLockForString(String lockName)
Deprecated.
This is provided only for migration purposes until a proper locking scheme is deployed throughout
genius and netvirt.
|
@Deprecated public static @NonNull ReentrantLock getLockForString(String lockName)
ReentrantLock
for a particular string.lockName
- Name of the lock, must not be nullNullPointerException
- if lockName
is nullpublic static @NonNull ReentrantLock getLockFor(org.opendaylight.yangtools.yang.binding.Identifier<?> identifier)
ReentrantLock
for an identifier.identifier
- Entity identifier, must not be nullNullPointerException
- if identifier
is nullpublic static @NonNull ReentrantLock getLockFor(org.opendaylight.yangtools.yang.binding.Identifiable<?> resource)
ReentrantLock
for a particular name.resource
- an Identifiable
resourceNullPointerException
- if resource
is nullCopyright © 2019 OpenDaylight. All rights reserved.