Commit 6d80a97f authored by Luna Riegel's avatar Luna Riegel
Browse files

Fix: Remove race condition in Schematron thread

parent 3152a987
...@@ -81,8 +81,6 @@ import java.io.InputStream; ...@@ -81,8 +81,6 @@ import java.io.InputStream;
import java.io.UncheckedIOException; import java.io.UncheckedIOException;
import java.nio.file.Files; import java.nio.file.Files;
import java.nio.file.Path; import java.nio.file.Path;
import java.text.ChoiceFormat;
import java.text.MessageFormat;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.HashMap; import java.util.HashMap;
...@@ -195,26 +193,31 @@ public class Checker { ...@@ -195,26 +193,31 @@ public class Checker {
if (config == null) { if (config == null) {
config = ValidationConfiguration.loadStandardValidationConfig(); config = ValidationConfiguration.loadStandardValidationConfig();
} }
Thread schematronThread = new Thread(() -> {
SvrlContentHandler handler = executeSchematronValidationIfAvailable(config, model.getFile()); Callable<SvrlContentHandler> schematronThread = () -> executeSchematronValidationIfAvailable(config, model.getFile());
if (handler != null) { ExecutorService executor = Executors.newSingleThreadExecutor();
handleSchematronResults(handler); Future<SvrlContentHandler> handlerFuture = executor.submit(schematronThread);
} executor.shutdown();
});
schematronThread.start();
checkCityModel(model, l); checkCityModel(model, l);
if (schematronThread.isAlive()) { if (!handlerFuture.isDone()) {
if (logger.isInfoEnabled()) {
logger.info(Localization.getText("Checker.schematronStillRunning")); logger.info(Localization.getText("Checker.schematronStillRunning"));
}
if(l !=null){ if(l !=null){
l.updateProgress(-0.5f); l.updateProgress(-0.5f);
} }
try{ }
schematronThread.join(); try {
logger.info(Localization.getText("Checker.schematronCompleted")); SvrlContentHandler handler = handlerFuture.get();
if (handler != null) {
handleSchematronResults(handler);
}
} catch (ExecutionException e) {
logger.error(e);
} catch (InterruptedException e) { } catch (InterruptedException e) {
logger.error(Localization.getText("Checker.schematronInterrupted"), e); logger.error(Localization.getText("Checker.schematronInterrupted"), e);
schematronThread.interrupt(); Thread.currentThread().interrupt();
}
} }
CacheManager.synchronizeCache(); CacheManager.synchronizeCache();
model.setValidated(createValidationPlan()); model.setValidated(createValidationPlan());
......
Supports Markdown
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