The ResourceTable locks on an attempt to acquire resources passing a array with duplicate names. Here is an example that demonstrates this:
import com.sun.javatest.ResourceTable;
public class Test {
public static void main(String[] args) throws InterruptedException {
ResourceTable table = new ResourceTable();
String[] locks = {"a", "b", "a"};
boolean ok = table.acquire(locks, 3000);
try {
if (!ok) {
System.out.println("Timeout");
} else {
System.out.println("Do work");
}
} finally {
table.release(locks);
}
}
}
The program below prints "Timeout" because the "a" resource occurs twice in "locks".
I think that it would be better if the ResourceTable removes duplicated resource names from the given array before acquiring the locks. Btw, that seems to be the initial design goal back in 1999 when the SortedStringVector.sort method had used for sorting the names, but this was changed later during the migration to the java.util.Arrays utilities.
import com.sun.javatest.ResourceTable;
public class Test {
public static void main(String[] args) throws InterruptedException {
ResourceTable table = new ResourceTable();
String[] locks = {"a", "b", "a"};
boolean ok = table.acquire(locks, 3000);
try {
if (!ok) {
System.out.println("Timeout");
} else {
System.out.println("Do work");
}
} finally {
table.release(locks);
}
}
}
The program below prints "Timeout" because the "a" resource occurs twice in "locks".
I think that it would be better if the ResourceTable removes duplicated resource names from the given array before acquiring the locks. Btw, that seems to be the initial design goal back in 1999 when the SortedStringVector.sort method had used for sorting the names, but this was changed later during the migration to the java.util.Arrays utilities.