Skip to content

Commit 24420e7

Browse files
tobiasdiezSiedlerchr
authored andcommitted
Fix #5862. It was indeed the throttler (at least it is working now for me) (#5868)
1 parent ac90ad2 commit 24420e7

File tree

4 files changed

+32
-2
lines changed

4 files changed

+32
-2
lines changed

src/main/java/org/jabref/gui/groups/GroupNodeViewModel.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ public GroupNodeViewModel(BibDatabaseContext databaseContext, StateManager state
9090
// The wrapper created by the FXCollections will set a weak listener on the wrapped list. This weak listener gets garbage collected. Hence, we need to maintain a reference to this list.
9191
entriesList = databaseContext.getDatabase().getEntries();
9292
entriesList.addListener(this::onDatabaseChanged);
93-
throttler = new DelayTaskThrottler(1000);
93+
throttler = taskExecutor.createThrottler(1000);
9494

9595
ObservableList<Boolean> selectedEntriesMatchStatus = EasyBind.map(stateManager.getSelectedEntries(), groupNode::matches);
9696
anySelectedEntriesMatched = BindingsHelper.any(selectedEntriesMatchStatus, matched -> matched);

src/main/java/org/jabref/gui/util/CurrentThreadTaskExecutor.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package org.jabref.gui.util;
22

3+
import java.util.WeakHashMap;
34
import java.util.concurrent.CompletableFuture;
45
import java.util.concurrent.ExecutionException;
56
import java.util.concurrent.Future;
@@ -8,6 +9,8 @@
89

910
import javafx.concurrent.Task;
1011

12+
import org.jabref.logic.util.DelayTaskThrottler;
13+
1114
import org.slf4j.Logger;
1215
import org.slf4j.LoggerFactory;
1316

@@ -19,6 +22,7 @@
1922
public class CurrentThreadTaskExecutor implements TaskExecutor {
2023

2124
private static final Logger LOGGER = LoggerFactory.getLogger(CurrentThreadTaskExecutor.class);
25+
private final WeakHashMap<DelayTaskThrottler, Void> throttlers = new WeakHashMap<>();
2226

2327
/**
2428
* Executes the task on the current thread. The code is essentially taken from {@link
@@ -60,7 +64,14 @@ public <V> Future<?> schedule(BackgroundTask<V> task, long delay, TimeUnit unit)
6064

6165
@Override
6266
public void shutdown() {
63-
// Nothing to do here
67+
throttlers.forEach((throttler, aVoid) -> throttler.shutdown());
68+
}
69+
70+
@Override
71+
public DelayTaskThrottler createThrottler(int delay) {
72+
DelayTaskThrottler throttler = new DelayTaskThrottler(delay);
73+
throttlers.put(throttler, null);
74+
return throttler;
6475
}
6576

6677
private class FailedFuture<T> implements Future<T> {

src/main/java/org/jabref/gui/util/DefaultTaskExecutor.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package org.jabref.gui.util;
22

33
import java.util.Objects;
4+
import java.util.WeakHashMap;
45
import java.util.concurrent.Callable;
56
import java.util.concurrent.CountDownLatch;
67
import java.util.concurrent.ExecutionException;
@@ -15,6 +16,8 @@
1516
import javafx.application.Platform;
1617
import javafx.concurrent.Task;
1718

19+
import org.jabref.logic.util.DelayTaskThrottler;
20+
1821
import org.slf4j.Logger;
1922
import org.slf4j.LoggerFactory;
2023

@@ -28,6 +31,7 @@ public class DefaultTaskExecutor implements TaskExecutor {
2831

2932
private final ExecutorService executor = Executors.newFixedThreadPool(5);
3033
private final ScheduledExecutorService scheduledExecutor = Executors.newScheduledThreadPool(2);
34+
private final WeakHashMap<DelayTaskThrottler, Void> throttlers = new WeakHashMap<>();
3135

3236
/**
3337
*
@@ -110,6 +114,14 @@ public <V> Future<?> schedule(BackgroundTask<V> task, long delay, TimeUnit unit)
110114
public void shutdown() {
111115
executor.shutdownNow();
112116
scheduledExecutor.shutdownNow();
117+
throttlers.forEach((throttler, aVoid) -> throttler.shutdown());
118+
}
119+
120+
@Override
121+
public DelayTaskThrottler createThrottler(int delay) {
122+
DelayTaskThrottler throttler = new DelayTaskThrottler(delay);
123+
throttlers.put(throttler, null);
124+
return throttler;
113125
}
114126

115127
private <V> Task<V> getJavaFXTask(BackgroundTask<V> task) {

src/main/java/org/jabref/gui/util/TaskExecutor.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55

66
import javafx.concurrent.Task;
77

8+
import org.jabref.logic.util.DelayTaskThrottler;
9+
810
/**
911
* An object that executes submitted {@link Task}s. This
1012
* interface provides a way of decoupling task submission from the
@@ -46,4 +48,9 @@ public interface TaskExecutor {
4648
* Shutdown the task executor.
4749
*/
4850
void shutdown();
51+
52+
/**
53+
* Creates a new task throttler, and registers it so that it gets properly shutdown.
54+
*/
55+
DelayTaskThrottler createThrottler(int delay);
4956
}

0 commit comments

Comments
 (0)