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