I am developing a javafx desktop application. The app is reading images from a directory then resize them and save related data to the database. Because the there are 10000 images, so I run the code inside a Service. Everything works fine until the images are all inside one directory (no sub-direcotries). When there are sub-directories the progress bar gets vanished as soon as the cursor reads a sub-directory and also the following error is desplayed in console. Any adeas?
public void startProcessing(String dirPath) {
Service service = new Service() {
@Override
protected Task createTask() {
return new Task() {
@Override
protected Object call() {
File dir = new File(dirPath);
for (final File f : dir.listFiles()) {
if (f.isFile()) {
BufferedImage img = null;
try {
img = ImageIO.read(f);
imgImpl.create(f.getName(), f.getPath(), f.length(),
img.getHeight(), img.getWidth(),
new Date(f.lastModified())
updateProgress(count, totalNumberOfFiles);
resizeImages(f.getPath(), f.getName());
count++;
} catch (final Exception e) {
updateProgress(count, totalNumberOfFiles);
count++;
}
} else if (f.isDirectory()) {
startProcessing(f.getAbsolutePath());
}
progressbar.setVisible(false);
}
return null;
}
};
}
};
progressbar.setVisible(true);
progressbar.progressProperty().bind(service.progressProperty());
service.start();
}
Jun 24, 2019 4:36:39 PM javafx.concurrent.Service lambda$static$1 WARNING: Uncaught throwable in javafx concurrent thread pool java.lang.IllegalStateException: Not on FX application thread; currentThread = Thread-4