VIVO-67 Fix for the broken pull request

As described in the comments on https://github.com/vivo-project/VIVO/pull/3
This commit is contained in:
j2blake 2013-06-14 13:13:37 -04:00
parent 9ada4eb84f
commit 5874b685cf
2 changed files with 9 additions and 16 deletions

View file

@ -32,10 +32,11 @@ public class OrganizationToPublicationsForSubOrganizationsFactory implements
return candidateModel;
} else {
Lock customLock = CustomLock.getInstance().getLock();
Lock customLock = CustomLock.getLock();
if (customLock.tryLock()) //Acquiring lock if available to construct the model
{
customLock.lock();
try
{
ModelConstructor model = new OrganizationToPublicationsForSubOrganizationsModelConstructor(uri, dataset);
Model constructedModel = model.getConstructedModel();
@ -45,8 +46,10 @@ public class OrganizationToPublicationsForSubOrganizationsFactory implements
uri,
OrganizationToPublicationsForSubOrganizationsModelConstructor.MODEL_TYPE),
constructedModel);
customLock.unlock();
return constructedModel;
} finally {
customLock.unlock();
}
}
else
{

View file

@ -1,3 +1,4 @@
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
package edu.cornell.mannlib.vitro.webapp.visualization.visutils;
import java.util.concurrent.locks.ReentrantLock;
@ -8,19 +9,8 @@ import java.util.concurrent.locks.Lock;
construction of the models to resolve concurrency issue*/
public final class CustomLock{
private static final CustomLock instance = new CustomLock();
private static Lock lock;
private CustomLock()
{
this.lock = new ReentrantLock();
}
public static CustomLock getInstance()
{
return instance;
}
private static final Lock lock = new ReentrantLock();
public static Lock getLock()
{
return lock;