Package com.tagtraum.core.util
Class ResourceLock<L extends Lock>
- java.lang.Object
-
- com.tagtraum.core.util.ResourceLock<L>
-
public class ResourceLock<L extends Lock> extends Object
Allows locking of a given resource. The resources must properly support theObject.equals(Object)
method. One usage for this class is the exclusive locking ofFile
s orPath
s for different threads asFileChannel.lock()
does not support intra-JVM locking.- Author:
- Hendrik Schreiber
-
-
Constructor Summary
Constructors Constructor Description ResourceLock()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected L
createLock(Object resource)
L
getLock(Object resource)
Get a lock object (not yet locked) for a given resource.L
lock(Object resource)
Obtain an exclusive lock for the given resource.
-
-
-
Method Detail
-
lock
public L lock(Object resource)
Obtain an exclusive lock for the given resource.- Parameters:
resource
- resource- Returns:
- lock (already locked).
-
getLock
public L getLock(Object resource)
Get a lock object (not yet locked) for a given resource.- Parameters:
resource
- resource- Returns:
- lock (not locked yet)
-
-