Object resource = null;
Vector list = null;
Resource r = null;
// get the list of resources
synchronized (resources) {
list = (Vector) resources.get(name);
if (list == null) {
list = new Vector(count);
resources.put(name, list);
}
}
// check for available resource
boolean newR = false; // this thread needs to create a new resource
synchronized (list) {
while (resource == null) {
// try to find an available resource
for (int i=0; i < list.size(); i++) {
if ((r = (Resource) list.elementAt(i)).isAvailable()) {
r.markInUse();
resource = r.getResource();
break;
}
}
// create new resource if limit not reached
if (resource == null) {
if (list.size() < count) {
r = new Resource();
list.addElement(r);
newR = true;
break;
}
// wait for the resource to free up
if (!newR) list.wait();
}
}
}
// if new resource created, initialize the resource
if (newR) {
try {
resource = createResource(name);
// XXX need to handle case when resource is null
} catch (Exception ex) {
/** IASRI 4660742
ex.printStackTrace();
**/
// START OF IASRI 4660742
_logger.log(Level.SEVERE,"enterprise_util.excep_rescache_getres",ex);
// END OF IASRI 4660742
}
synchronized (list) {
r.setResource(resource);
r.markInUse();
}
}
return resource;