Skip to content

Commit 4b936a3

Browse files
committed
experiment with threading
1 parent 08f243a commit 4b936a3

File tree

3 files changed

+28
-9
lines changed

3 files changed

+28
-9
lines changed

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

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import java.util.Optional;
66
import java.util.stream.Collectors;
77

8+
import javafx.application.Platform;
89
import javafx.beans.InvalidationListener;
910
import javafx.beans.WeakInvalidationListener;
1011
import javafx.beans.binding.Bindings;
@@ -57,7 +58,7 @@ public class GroupNodeViewModel {
5758
private final BooleanBinding allSelectedEntriesMatched;
5859
private final TaskExecutor taskExecutor;
5960
private final CustomLocalDragboard localDragBoard;
60-
private final ObservableList<BibEntry> entriesList;
61+
private ObservableList<BibEntry> entriesList;
6162
private final PreferencesService preferencesService;
6263
private final InvalidationListener onInvalidatedGroup = (listener) -> refreshGroup();
6364

@@ -91,8 +92,11 @@ public GroupNodeViewModel(BibDatabaseContext databaseContext, StateManager state
9192

9293
// Register listener
9394
// 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.
94-
entriesList = databaseContext.getDatabase().getEntries();
95-
entriesList.addListener(this::onDatabaseChanged);
95+
Platform.runLater(()-> {
96+
entriesList = databaseContext.getDatabase().getEntries();
97+
entriesList.addListener(this::onDatabaseChanged);
98+
});
99+
96100

97101
EasyObservableList<Boolean> selectedEntriesMatchStatus = EasyBind.map(stateManager.getSelectedEntries(), groupNode::matches);
98102
anySelectedEntriesMatched = selectedEntriesMatchStatus.anyMatch(matched -> matched);

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

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,14 @@ protected void sourceChanged(ListChangeListener.Change<? extends T> change) {
2323
} else {
2424
CountDownLatch latch = new CountDownLatch(1);
2525
Platform.runLater(() -> {
26-
fireChange(change);
26+
try {
27+
fireChange(change);
28+
29+
}
30+
finally
31+
{
32+
latch.countDown();
33+
}
2734
});
2835

2936
try {

src/main/java/org/jabref/logic/shared/DBMSSynchronizer.java

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ public void initializeDatabases() throws DatabaseNotSupportedException {
191191
* {@link BibEntry}.
192192
*/
193193
@Override
194-
public void synchronizeLocalDatabase() {
194+
public synchronized void synchronizeLocalDatabase() {
195195
if (!checkCurrentConnection()) {
196196
return;
197197
}
@@ -206,15 +206,20 @@ public void synchronizeLocalDatabase() {
206206
for (Map.Entry<Integer, Integer> idVersionEntry : idVersionMap.entrySet()) {
207207
boolean remoteEntryMatchingOneLocalEntryFound = false;
208208
for (BibEntry localEntry : localEntries) {
209-
if (idVersionEntry.getKey().equals(localEntry.getSharedBibEntryData().getSharedID())) {
210-
remoteEntryMatchingOneLocalEntryFound = true;
209+
remoteEntryMatchingOneLocalEntryFound = true;
210+
211211
if (idVersionEntry.getValue() > localEntry.getSharedBibEntryData().getVersion()) {
212212
Optional<BibEntry> sharedEntry = dbmsProcessor.getSharedEntry(idVersionEntry.getKey());
213213
if (sharedEntry.isPresent()) {
214214
// update fields
215215
localEntry.setType(sharedEntry.get().getType(), EntriesEventSource.SHARED);
216216
localEntry.getSharedBibEntryData()
217217
.setVersion(sharedEntry.get().getSharedBibEntryData().getVersion());
218+
219+
220+
taskExecutor.runInFXThread(()-> {
221+
222+
218223
sharedEntry.get().getFieldMap().forEach(
219224
// copy remote values to local entry
220225
(field, value) -> localEntry.setField(field, value, EntriesEventSource.SHARED)
@@ -226,18 +231,21 @@ public void synchronizeLocalDatabase() {
226231
.forEach(
227232
field -> localEntry.clearField(field, EntriesEventSource.SHARED)
228233
);
234+
});
229235
}
230236
}
231237
}
232-
}
238+
233239
if (!remoteEntryMatchingOneLocalEntryFound) {
234240
entriesToInsertIntoLocalDatabase.add(idVersionEntry.getKey());
235241
}
236242
}
237243

238244
if (!entriesToInsertIntoLocalDatabase.isEmpty()) {
245+
246+
taskExecutor.runInFXThread( () -> bibDatabase.insertEntries(dbmsProcessor.getSharedEntries(entriesToInsertIntoLocalDatabase), EntriesEventSource.SHARED));
239247
// in case entries should be added into the local database, insert them
240-
bibDatabase.insertEntries(dbmsProcessor.getSharedEntries(entriesToInsertIntoLocalDatabase), EntriesEventSource.SHARED);
248+
// bibDatabase.insertEntries(dbmsProcessor.getSharedEntries(entriesToInsertIntoLocalDatabase), EntriesEventSource.SHARED);
241249
}
242250
}
243251

0 commit comments

Comments
 (0)