Package com.sun.javatest
Class ResourceTable
- java.lang.Object
-
- com.sun.javatest.ResourceTable
-
public class ResourceTable extends java.lang.Object
A table providing simple named locks for arbitrary resources.
-
-
Constructor Summary
Constructors Constructor Description ResourceTable()
Create a resource table.ResourceTable(int initialSize)
Create a resource table of a specified size.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
acquire(java.lang.String[] resourceNames, int timeout)
Try to acquire a set of named locks.void
release(java.lang.String... resourceNames)
Release a set of previously acquired locks.java.util.Map<java.lang.String,java.lang.Thread>
table()
Returns unmodifiable copy of the resource table.
-
-
-
Method Detail
-
acquire
public boolean acquire(java.lang.String[] resourceNames, int timeout) throws java.lang.InterruptedException
Try to acquire a set of named locks. To avoid deadlocks, the locks are acquired in a canonical order (alphabetical by name.)- Parameters:
resourceNames
- a list of names identifying locks to be acquired.timeout
- a maximum time, in milliseconds to ait for the locks to become available.- Returns:
- true if and only if all the locks were successfully acquired
- Throws:
java.lang.InterruptedException
- is the method was interrupted while waiting for the locks to become available.
-
release
public void release(java.lang.String... resourceNames)
Release a set of previously acquired locks. The named locks are only released if currently owned by the same thread that acquired them.- Parameters:
resourceNames
- the names of the locks to be released
-
table
public java.util.Map<java.lang.String,java.lang.Thread> table()
Returns unmodifiable copy of the resource table. Table contains resource names mapped to threads that originally calledacquire
method. Please note that query operations on the returned map "read through" to the internal original map which could be changing over time.- Returns:
- unmodifiable resource table
-
-