[DS-707] Multithreaded correctness

git-svn-id: http://scm.dspace.org/svn/repo/dspace/trunk@5644 9c30dcfa-912a-0410-8fc2-9e0234be79fd
This commit is contained in:
Graham Triggs
2010-10-26 10:20:33 +00:00
parent 0cf92c1cf3
commit a35bf6ca6c
3 changed files with 53 additions and 34 deletions

View File

@@ -85,6 +85,16 @@ public class DCInputAuthority extends SelfNamedPlugin implements ChoiceAuthority
} }
public static String[] getPluginNames() public static String[] getPluginNames()
{
if (pluginNames == null)
{
initPluginNames();
}
return (String[]) ArrayUtils.clone(pluginNames);
}
private static synchronized void initPluginNames()
{ {
if (pluginNames == null) if (pluginNames == null)
{ {
@@ -109,7 +119,6 @@ public class DCInputAuthority extends SelfNamedPlugin implements ChoiceAuthority
pluginNames = names.toArray(new String[names.size()]); pluginNames = names.toArray(new String[names.size()]);
log.debug("Got plugin names = "+Arrays.deepToString(pluginNames)); log.debug("Got plugin names = "+Arrays.deepToString(pluginNames));
} }
return (String[]) ArrayUtils.clone(pluginNames);
} }
// once-only load of values and labels // once-only load of values and labels

View File

@@ -105,6 +105,16 @@ public class DSpaceControlledVocabulary extends SelfNamedPlugin implements Choic
} }
public static String[] getPluginNames() public static String[] getPluginNames()
{
if (pluginNames == null)
{
initPluginNames();
}
return (String[]) ArrayUtils.clone(pluginNames);
}
private static synchronized void initPluginNames()
{ {
if (pluginNames == null) if (pluginNames == null)
{ {
@@ -125,7 +135,6 @@ public class DSpaceControlledVocabulary extends SelfNamedPlugin implements Choic
pluginNames = names.toArray(new String[names.size()]); pluginNames = names.toArray(new String[names.size()]);
log.info("Got plugin names = "+Arrays.deepToString(pluginNames)); log.info("Got plugin names = "+Arrays.deepToString(pluginNames));
} }
return (String[]) ArrayUtils.clone(pluginNames);
} }
private void init() private void init()

View File

@@ -1020,7 +1020,7 @@ public class OAIHarvester {
/** /**
* Start harvest scheduler. * Start harvest scheduler.
*/ */
public static void startNewScheduler() throws SQLException, AuthorizeException { public static synchronized void startNewScheduler() throws SQLException, AuthorizeException {
Context c = new Context(); Context c = new Context();
HarvestedCollection.exists(c); HarvestedCollection.exists(c);
c.complete(); c.complete();
@@ -1037,7 +1037,7 @@ public class OAIHarvester {
/** /**
* Stop an active harvest scheduler. * Stop an active harvest scheduler.
*/ */
public static void stopScheduler() throws SQLException, AuthorizeException { public static synchronized void stopScheduler() throws SQLException, AuthorizeException {
synchronized(HarvestScheduler.lock) { synchronized(HarvestScheduler.lock) {
HarvestScheduler.interrupt = HarvestScheduler.HARVESTER_INTERRUPT_STOP; HarvestScheduler.interrupt = HarvestScheduler.HARVESTER_INTERRUPT_STOP;
HarvestScheduler.lock.notify(); HarvestScheduler.lock.notify();
@@ -1187,34 +1187,35 @@ public class OAIHarvester {
{ {
try try
{ {
synchronized(interrupt) { synchronized (HarvestScheduler.class) {
switch (interrupt) switch (interrupt)
{ {
case HARVESTER_INTERRUPT_NONE: case HARVESTER_INTERRUPT_NONE:
break; break;
case HARVESTER_INTERRUPT_INSERT_THREAD: case HARVESTER_INTERRUPT_INSERT_THREAD:
interrupt = HARVESTER_INTERRUPT_NONE; interrupt = HARVESTER_INTERRUPT_NONE;
addThread(interruptValue); addThread(interruptValue);
interruptValue = 0; interruptValue = 0;
break; break;
case HARVESTER_INTERRUPT_PAUSE: case HARVESTER_INTERRUPT_PAUSE:
interrupt = HARVESTER_INTERRUPT_NONE; interrupt = HARVESTER_INTERRUPT_NONE;
synchronized(status) { status = HARVESTER_STATUS_PAUSED;
status = HARVESTER_STATUS_PAUSED; case HARVESTER_INTERRUPT_STOP:
} interrupt = HARVESTER_INTERRUPT_NONE;
while(interrupt != HARVESTER_INTERRUPT_RESUME && interrupt != HARVESTER_INTERRUPT_STOP) { status = HARVESTER_STATUS_STOPPED;
Thread.sleep(1000); return;
} }
if (interrupt != HARVESTER_INTERRUPT_STOP) }
{
break; if (status == HARVESTER_STATUS_PAUSED) {
} while(interrupt != HARVESTER_INTERRUPT_RESUME && interrupt != HARVESTER_INTERRUPT_STOP) {
case HARVESTER_INTERRUPT_STOP: Thread.sleep(1000);
interrupt = HARVESTER_INTERRUPT_NONE; }
status = HARVESTER_STATUS_STOPPED; if (interrupt != HARVESTER_INTERRUPT_STOP)
return; {
} break;
} }
}
status = HARVESTER_STATUS_RUNNING; status = HARVESTER_STATUS_RUNNING;
@@ -1229,7 +1230,7 @@ public class OAIHarvester {
// Stage #2: start up all the threads currently in the queue up to the maximum number // Stage #2: start up all the threads currently in the queue up to the maximum number
while (!harvestThreads.isEmpty()) { while (!harvestThreads.isEmpty()) {
synchronized(activeThreads) { synchronized(HarvestScheduler.class) {
activeThreads++; activeThreads++;
} }
Thread activeThread = new Thread(harvestThreads.pop()); Thread activeThread = new Thread(harvestThreads.pop());
@@ -1390,7 +1391,7 @@ public class OAIHarvester {
context.abort(); context.abort();
} }
synchronized (HarvestScheduler.activeThreads) { synchronized (HarvestScheduler.class) {
HarvestScheduler.activeThreads--; HarvestScheduler.activeThreads--;
} }
} }