Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix freezing when running cleanup file operations like rename #3315

Merged
merged 5 commits into from
Oct 28, 2017
Merged
Show file tree
Hide file tree
Changes from 3 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
3 changes: 2 additions & 1 deletion src/main/java/org/jabref/gui/actions/CleanupAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import org.jabref.gui.cleanup.CleanupPresetPanel;
import org.jabref.gui.undo.NamedCompound;
import org.jabref.gui.undo.UndoableFieldChange;
import org.jabref.gui.util.DefaultTaskExecutor;
import org.jabref.gui.util.component.CheckBoxMessage;
import org.jabref.gui.worker.AbstractWorker;
import org.jabref.logic.cleanup.CleanupPreset;
Expand Down Expand Up @@ -144,7 +145,7 @@ private void doCleanup(CleanupPreset preset, BibEntry entry, NamedCompound ce) {
// Create and run cleaner
CleanupWorker cleaner = new CleanupWorker(panel.getBibDatabaseContext(), preferences.getCleanupPreferences(
Globals.journalAbbreviationLoader));
List<FieldChange> changes = cleaner.cleanup(preset, entry);
List<FieldChange> changes = DefaultTaskExecutor.runInJavaFXThread(() -> cleaner.cleanup(preset, entry));

unsuccessfulRenames = cleaner.getUnsuccessfulRenames();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@ public void rename() {

if (confirm) {
Optional<Path> fileConflictCheck = pdfCleanup.findExistingFile(linkedFile, entry);

performRenameWithConflictCheck(file, pdfCleanup, targetFileName, fileConflictCheck);
}
} else {
Expand Down
16 changes: 13 additions & 3 deletions src/main/java/org/jabref/gui/util/DefaultTaskExecutor.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,17 @@ public class DefaultTaskExecutor implements TaskExecutor {

private static final Log LOGGER = LogFactory.getLog(DefaultTaskExecutor.class);

private ExecutorService executor = Executors.newFixedThreadPool(5);
private static final ExecutorService executor = Executors.newFixedThreadPool(5);

public static <V> V runInJavaFXThread(Callable<V> callable) {
FutureTask<V> task = new FutureTask<>(callable);
Platform.runLater(task);

if (!Platform.isFxApplicationThread()) {
Platform.runLater(task);
} else {
executor.submit(task);
}

try {
return task.get();
} catch (InterruptedException | ExecutionException e) {
Expand All @@ -37,7 +43,11 @@ public static <V> V runInJavaFXThread(Callable<V> callable) {
}

public static void runInJavaFXThread(Runnable runnable) {
Platform.runLater(runnable);
if (!Platform.isFxApplicationThread()) {
Platform.runLater(runnable);
} else {
executor.submit(runnable);
}
}

@Override
Expand Down