-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'upstream/master' into customizeEntrydlg
# By dependabot-preview[bot] (2) and others # Via GitHub (1) and github actions (1) * upstream/master: New Crowdin translations (#5864) Bump antlr4 from 4.7.2 to 4.8-1 (#5852) Reintroducing master table index column (#5844) Bump antlr4-runtime from 4.7.2 to 4.8-1 (#5851) Improve performance by throttling database change events (#5843) Squashed 'src/main/resources/csl-styles/' changes from 9c0f5c6..f0c7374 # Conflicts: # src/main/resources/l10n/JabRef_en.properties
- Loading branch information
Showing
32 changed files
with
496 additions
and
213 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
src/main/java/org/jabref/logic/util/DelayTaskThrottler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package org.jabref.logic.util; | ||
|
||
import java.util.concurrent.Future; | ||
import java.util.concurrent.RejectedExecutionException; | ||
import java.util.concurrent.ScheduledThreadPoolExecutor; | ||
import java.util.concurrent.TimeUnit; | ||
|
||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
/** | ||
* This class allows to throttle a list of tasks. | ||
* Use case: you have an event that occurs often, and every time you want to invoke the same task. | ||
* However, if a lot of events happen in a relatively short time span, then only one task should be invoked. | ||
* | ||
* @implNote Once {@link #schedule(Runnable)} is called, the task is delayed for a given time span. | ||
* If during this time, {@link #schedule(Runnable)} is called again, then the original task is canceled and the new one scheduled. | ||
*/ | ||
public class DelayTaskThrottler { | ||
|
||
private static final Logger LOGGER = LoggerFactory.getLogger(DelayTaskThrottler.class); | ||
|
||
private final ScheduledThreadPoolExecutor executor; | ||
private final int delay; | ||
|
||
private Future<?> scheduledTask; | ||
|
||
/** | ||
* @param delay delay in milliseconds | ||
*/ | ||
public DelayTaskThrottler(int delay) { | ||
this.delay = delay; | ||
this.executor = new ScheduledThreadPoolExecutor(1); | ||
this.executor.setRemoveOnCancelPolicy(true); | ||
} | ||
|
||
public void schedule(Runnable command) { | ||
if (scheduledTask != null) { | ||
scheduledTask.cancel(false); | ||
} | ||
try { | ||
scheduledTask = executor.schedule(command, delay, TimeUnit.MILLISECONDS); | ||
} catch (RejectedExecutionException e) { | ||
LOGGER.debug("Rejecting while another process is already running."); | ||
} | ||
} | ||
|
||
public void shutdown() { | ||
executor.shutdown(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.