Package de.bmiag.tapir.util.resource
Class SharedResourcePool
- java.lang.Object
-
- de.bmiag.tapir.util.resource.SharedResourcePool
-
@Component("tapirSharedResourcePool") public class SharedResourcePool extends java.lang.Object
TheSharedResourcePool
provides the possibility to lock resources in order to synchronize them. Clients which need to obtain a shared resource can query a lock by callinglockResource(Object)
.- Since:
- 2.0.0
- Author:
- Oliver Libutzki <[email protected]>
-
-
Constructor Summary
Constructors Constructor Description SharedResourcePool()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
lockResource(java.lang.Object resource)
Queries a resource.void
unlockResource(java.lang.Object resource)
Unlocks a resource.
-
-
-
Method Detail
-
lockResource
public void lockResource(java.lang.Object resource)
Queries a resource. If the resource is not locked, the lock is acquired for the current thread and the method returns immediately. Otherwise the method waits until the resource is unlocked or a timeout occurred. If the lock cannot be acquired aRuntimeException
is thrown. The given resource is compared by itsObject.equals(Object)
method.- Parameters:
resource
- the resource to lock- Throws:
java.lang.RuntimeException
- Thrown if the lock cannot be acquired within the time specified bytimeOutInSeconds
.- Since:
- 2.0.0
-
unlockResource
public void unlockResource(java.lang.Object resource)
Unlocks a resource. The given resource'sObject.equals(Object)
method has to return true if it's compared to the locked resource.- Parameters:
resource
- the resource to unlock- Since:
- 2.0.0
-
-