Commit a4720d36 authored by Matija Obreza's avatar Matija Obreza

Properly terminate monitoring thread when done

parent 08967a90
......@@ -113,7 +113,7 @@ public class PushDialog extends Dialog {
protected DataSourceLoader dataSourceLoader;
BlockingQueue<Runnable> linkedBlockingDeque = new LinkedBlockingDeque<Runnable>(MAX_UPLOAD_THREADS + 2);
private ThreadPoolExecutor executorService = new ThreadPoolExecutor(1, 1 + MAX_UPLOAD_THREADS, 10, TimeUnit.SECONDS, linkedBlockingDeque, new ThreadPoolExecutor.CallerRunsPolicy());
private ThreadPoolExecutor executorService = new ThreadPoolExecutor(2, 1 + MAX_UPLOAD_THREADS, 10, TimeUnit.SECONDS, linkedBlockingDeque, new ThreadPoolExecutor.CallerRunsPolicy());
protected Object result;
protected Shell shell;
......@@ -304,7 +304,7 @@ public class PushDialog extends Dialog {
}
}
if (futures.size() > 1) {
if (futures.size() > 0) {
_log.warn("Jobs still running: " + futures.size());
}
......@@ -417,7 +417,7 @@ public class PushDialog extends Dialog {
final RowReader rowReader = dataSourceLoader.createRowReader(dataSourceSheet, dataSource);
rowReader.setSkipRows(dataSourceSheet.getHeaderRowIndex() + 1);
Future<?> future = executorService.submit(new Runnable() {
executorService.submit(new Runnable() {
@Override
public void run() {
int count = 0;
......@@ -467,8 +467,6 @@ public class PushDialog extends Dialog {
}
});
futures.add(future);
} catch (IOException e) {
_log.error(e.getMessage(), e);
} catch (UnsupportedDataFormatException e) {
......@@ -492,7 +490,7 @@ public class PushDialog extends Dialog {
final int extraSkipRows = this.pushProgress.extraSkipRows;
Future<?> future = executorService.submit(() -> {
executorService.submit(() -> {
final Map<String, TimedList<ObjectNode>> instCodeMap = new HashMap<String, TimedList<ObjectNode>>();
......@@ -541,8 +539,8 @@ public class PushDialog extends Dialog {
if (sb.length() > 0) {
sb.insert(0, "Pending: ");
}
if (executorService.getActiveCount() > 1 && futures.size() > 1) {
sb.insert(0, " Queued uploads: " + ((futures.size() - 1) - executorService.getActiveCount()) + " ");
if (executorService.getActiveCount() > 1 && futures.size() > 0) {
sb.insert(0, " Queued uploads: " + (futures.size() - executorService.getActiveCount()) + " ");
sb.insert(0, "Active uploads: " + (executorService.getActiveCount() - 1));
}
if (StringUtils.isBlank(sb)) {
......@@ -741,15 +739,8 @@ public class PushDialog extends Dialog {
} catch (InterruptedException e) {
break;
}
for (int i = futures.size() - 1; i >= 0; i--) {
Future<?> f = futures.get(i);
if (f.isDone()) {
futures.remove(f);
}
}
if (futures.size() > 1) {
if (futures.size() > 0) {
_log.debug("Waiting for uploads still running: " + futures.size());
}
......@@ -777,8 +768,6 @@ public class PushDialog extends Dialog {
_log.info("Done.");
}
});
futures.add(future);
}
public void setDataSourceSheet(IDataSourceSheet dss) {
......@@ -866,6 +855,7 @@ public class PushDialog extends Dialog {
});
futures.add(future);
_log.debug("Queueing data for instCode=" + instCode + " size=" + accns.size());
}
public void setDataSource(IDataSource dataSource) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment