Browse Source

Fix bug of not terminating all service and postback threads at end of broadcast.

tags/1.0.26
ymlam 2 years ago
parent
commit
4ab8cd54d1
2 changed files with 14 additions and 4 deletions
  1. +10
    -4
      src/main/java/altk/comm/engine/Broadcast.java
  2. +4
    -0
      src/main/java/altk/comm/engine/Postback.java

+ 10
- 4
src/main/java/altk/comm/engine/Broadcast.java View File

@@ -323,10 +323,11 @@ public abstract class Broadcast
// Get a batch of jobs, if available // Get a batch of jobs, if available
myLogger.debug("Looking for jobs"); myLogger.debug("Looking for jobs");
List<Job> batch = new ArrayList<Job>(); List<Job> batch = new ArrayList<Job>();
int batchSize = getJobBatchSize();
synchronized(readyQueue) synchronized(readyQueue)
{ {
// We we are to get a batch of more than one, let us fill in the rest. // We we are to get a batch of more than one, let us fill in the rest.
for (int i = 0; i < getJobBatchSize(); i++)
for (int i = 0; i < batchSize; i++)
{ {
Job job = readyQueue.poll(); Job job = readyQueue.poll();
if (job == null) break; if (job == null) break;
@@ -349,7 +350,7 @@ public abstract class Broadcast
continue; continue;
} }
} }
updateServiceActivityCount(batch.size());
updateServiceActivityCount(batchSize);
} }


// Process jobs. // Process jobs.
@@ -374,15 +375,16 @@ public abstract class Broadcast
catch (EngineException e) catch (EngineException e)
{ {
// Aborting // Aborting
myLogger.error("Caught unexpected Exception", e);
setState(BroadcastState.ABORTING, e.errorCodeText, e.errorText); setState(BroadcastState.ABORTING, e.errorCodeText, e.errorText);
updateServiceActivityCount(-batch.size());
updateServiceActivityCount(-batchSize);
} }
catch (Throwable t) catch (Throwable t)
{ {
// This is unexpected. Log stack trace // This is unexpected. Log stack trace
myLogger.error("Caught unexpected Throwable", t); myLogger.error("Caught unexpected Throwable", t);
terminate(BroadcastState.ABORTED, t + ": " + t.getMessage()); terminate(BroadcastState.ABORTED, t + ": " + t.getMessage());
updateServiceActivityCount(-batch.size());
updateServiceActivityCount(-batchSize);
} }
if (sleepBetweenJobs > 0) if (sleepBetweenJobs > 0)
{ {
@@ -398,6 +400,10 @@ public abstract class Broadcast
} }
// Exit thread // Exit thread
myLogger.info("Thread terminating"); myLogger.info("Thread terminating");
synchronized(readyQueue)
{
readyQueue.notify();
}
System.out.println(getName() + " terminating"); System.out.println(getName() + " terminating");
closeServiceProvider(serviceProviderPeer); closeServiceProvider(serviceProviderPeer);
} }


+ 4
- 0
src/main/java/altk/comm/engine/Postback.java View File

@@ -165,6 +165,10 @@ public class Postback
case STOP: case STOP:
myLogger.info(getName() + " terminating"); myLogger.info(getName() + " terminating");
System.out.println(getName() + " terminating"); System.out.println(getName() + " terminating");
synchronized(postQueue)
{
postQueue.notify();
}
return; return;
case WAIT: case WAIT:
synchronized (postQueue) synchronized (postQueue)


Loading…
Cancel
Save