Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,16 @@ public synchronized int getJobCount(final JavaScriptJobFilter filter) {
}
return count;
}

public synchronized int getNonPeriodicJobsCount() {
int count = 0;
for (final JavaScriptJob job : scheduledJobsQ_)
if (!job.isPeriodic())
count++;
if (currentlyRunningJob_ != null && !currentlyRunningJob_.isPeriodic())
count++;
return count;
}

/** {@inheritDoc} */
@Override
Expand Down Expand Up @@ -185,29 +195,29 @@ public int waitForJobs(final long timeoutMillis) {
if (debug) {
LOG.debug("Waiting for all jobs to finish (will wait max " + timeoutMillis + " millis).");
}
if (timeoutMillis > 0) {
long now = System.currentTimeMillis();
final long end = now + timeoutMillis;
synchronized (this) {
if (timeoutMillis > 0) {
long now = System.currentTimeMillis();
final long end = now + timeoutMillis;

synchronized (this) {
while (getJobCount() > 0 && now < end) {
while (getNonPeriodicJobsCount() > 0 && now < end) {
try {
wait(end - now);
}
catch (final InterruptedException e) {
} catch (final InterruptedException e) {
LOG.error("InterruptedException while in waitForJobs", e);
}
// maybe a change triggers the wakup; we have to recalculate the
// wait time
now = System.currentTimeMillis();
}
}
}
final int jobs = getJobCount();
if (debug) {
LOG.debug("Finished waiting for all jobs to finish (final job count is " + jobs + ").");
}
return jobs;
}
final int jobs = getNonPeriodicJobsCount();
if (debug && jobs > 0) {
LOG.debug("Finished waiting for all jobs to finish (final job count is " + jobs + ").");
printQueue();
}
return jobs;
}
}

/** {@inheritDoc} */
Expand Down