Class ResourceTable

java.lang.Object
com.sun.javatest.ResourceTable

public class ResourceTable extends Object
A table providing simple named locks for arbitrary resources.
  • Constructor Details

    • ResourceTable

      public ResourceTable()
      Create a resource table.
    • ResourceTable

      public ResourceTable(int initialSize)
      Create a resource table of a specified size.
      Parameters:
      initialSize - a hint as to the initial capacity to make the table
  • Method Details

    • acquire

      public boolean acquire(String[] resourceNames, int timeout) throws 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:
      InterruptedException - is the method was interrupted while waiting for the locks to become available.
    • release

      public void release(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 Map<String,Thread> table()
      Returns unmodifiable copy of the resource table. Table contains resource names mapped to threads that originally called acquire 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