From c76ce9d2d94d40b2b749e1af6821156c96d1f521 Mon Sep 17 00:00:00 2001 From: Tobias Diez Date: Sat, 28 Sep 2019 12:26:37 +0200 Subject: [PATCH 1/2] Remove application insights configuration file to improve startup time --- src/main/resources/ApplicationInsights.xml | 25 ---------------------- 1 file changed, 25 deletions(-) delete mode 100644 src/main/resources/ApplicationInsights.xml diff --git a/src/main/resources/ApplicationInsights.xml b/src/main/resources/ApplicationInsights.xml deleted file mode 100644 index c037e786bee..00000000000 --- a/src/main/resources/ApplicationInsights.xml +++ /dev/null @@ -1,25 +0,0 @@ - - - - - - False - - - - - - - - - - - - From 5166febb21f7ad17470968a7d2da55d12ae5653e Mon Sep 17 00:00:00 2001 From: Tobias Diez Date: Sat, 28 Sep 2019 20:14:20 +0200 Subject: [PATCH 2/2] Run version worker delayed Delay the check if an updated version exists by a few seconds to speed-up the application start. --- src/main/java/org/jabref/JabRefGUI.java | 2 +- .../jabref/gui/help/SearchForUpdateAction.java | 2 +- .../java/org/jabref/gui/help/VersionWorker.java | 17 +++++++++++------ .../org/jabref/gui/util/BackgroundTask.java | 5 +++++ .../gui/util/CurrentThreadTaskExecutor.java | 5 +++++ .../jabref/gui/util/DefaultTaskExecutor.java | 15 ++++++++++++--- .../java/org/jabref/gui/util/TaskExecutor.java | 13 +++++++++++++ 7 files changed, 48 insertions(+), 11 deletions(-) diff --git a/src/main/java/org/jabref/JabRefGUI.java b/src/main/java/org/jabref/JabRefGUI.java index 66fe3694ffa..9a389f454d2 100644 --- a/src/main/java/org/jabref/JabRefGUI.java +++ b/src/main/java/org/jabref/JabRefGUI.java @@ -58,7 +58,7 @@ public JabRefGUI(Stage mainStage, List argsDatabases, boolean isBl openWindow(mainStage); new VersionWorker(Globals.BUILD_INFO.getVersion(), Globals.prefs.getVersionPreferences().getIgnoredVersion(), mainFrame.getDialogService(), Globals.TASK_EXECUTOR) - .checkForNewVersionAsync(false); + .checkForNewVersionDelayed(); } private void openWindow(Stage mainStage) { diff --git a/src/main/java/org/jabref/gui/help/SearchForUpdateAction.java b/src/main/java/org/jabref/gui/help/SearchForUpdateAction.java index c1d951aaa01..3e85c2fc9e1 100644 --- a/src/main/java/org/jabref/gui/help/SearchForUpdateAction.java +++ b/src/main/java/org/jabref/gui/help/SearchForUpdateAction.java @@ -23,6 +23,6 @@ public SearchForUpdateAction(BuildInfo buildInfo, VersionPreferences versionPref @Override public void execute() { new VersionWorker(buildInfo.getVersion(), versionPreferences.getIgnoredVersion(), dialogService, taskExecutor) - .checkForNewVersionAsync(true); + .checkForNewVersionAsync(); } } diff --git a/src/main/java/org/jabref/gui/help/VersionWorker.java b/src/main/java/org/jabref/gui/help/VersionWorker.java index 2250be98a8f..f89eede48b9 100644 --- a/src/main/java/org/jabref/gui/help/VersionWorker.java +++ b/src/main/java/org/jabref/gui/help/VersionWorker.java @@ -4,6 +4,7 @@ import java.util.List; import java.util.Objects; import java.util.Optional; +import java.util.concurrent.TimeUnit; import org.jabref.gui.DialogService; import org.jabref.gui.util.BackgroundTask; @@ -54,16 +55,20 @@ private Optional getNewVersion() throws IOException { return installedVersion.shouldBeUpdatedTo(availableVersions); } - /** - * @param manualExecution if this versions check is executed automatically (eg. on startup) or manually by the user - */ - public void checkForNewVersionAsync(boolean manualExecution) { + public void checkForNewVersionAsync() { BackgroundTask.wrap(this::getNewVersion) - .onSuccess(version -> showUpdateInfo(version, manualExecution)) - .onFailure(exception -> showConnectionError(exception, manualExecution)) + .onSuccess(version -> showUpdateInfo(version, true)) + .onFailure(exception -> showConnectionError(exception, true)) .executeWith(taskExecutor); } + public void checkForNewVersionDelayed() { + BackgroundTask.wrap(this::getNewVersion) + .onSuccess(version -> showUpdateInfo(version, false)) + .onFailure(exception -> showConnectionError(exception, false)) + .scheduleWith(taskExecutor, 30, TimeUnit.SECONDS); + } + /** * Prints the connection problem to the status bar and shows a dialog if it was executed manually */ diff --git a/src/main/java/org/jabref/gui/util/BackgroundTask.java b/src/main/java/org/jabref/gui/util/BackgroundTask.java index 7b0b8df1424..c07f3b70485 100644 --- a/src/main/java/org/jabref/gui/util/BackgroundTask.java +++ b/src/main/java/org/jabref/gui/util/BackgroundTask.java @@ -2,6 +2,7 @@ import java.util.concurrent.Callable; import java.util.concurrent.Future; +import java.util.concurrent.TimeUnit; import java.util.function.Consumer; import java.util.function.Function; @@ -149,6 +150,10 @@ public Future executeWith(TaskExecutor taskExecutor) { return taskExecutor.execute(this); } + public Future scheduleWith(TaskExecutor taskExecutor, long delay, TimeUnit unit) { + return taskExecutor.schedule(this, delay, unit); + } + /** * Sets the {@link Runnable} that is invoked after the task is finished, irrespectively if it was successful or * failed with an error. diff --git a/src/main/java/org/jabref/gui/util/CurrentThreadTaskExecutor.java b/src/main/java/org/jabref/gui/util/CurrentThreadTaskExecutor.java index a18bf6fc5aa..ff7ef256068 100644 --- a/src/main/java/org/jabref/gui/util/CurrentThreadTaskExecutor.java +++ b/src/main/java/org/jabref/gui/util/CurrentThreadTaskExecutor.java @@ -53,6 +53,11 @@ public Future execute(Task task) { return task; } + @Override + public Future schedule(BackgroundTask task, long delay, TimeUnit unit) { + return execute(task); + } + @Override public void shutdown() { // Nothing to do here diff --git a/src/main/java/org/jabref/gui/util/DefaultTaskExecutor.java b/src/main/java/org/jabref/gui/util/DefaultTaskExecutor.java index b1cde500093..e0f8b8c6d7f 100644 --- a/src/main/java/org/jabref/gui/util/DefaultTaskExecutor.java +++ b/src/main/java/org/jabref/gui/util/DefaultTaskExecutor.java @@ -8,6 +8,8 @@ import java.util.concurrent.Executors; import java.util.concurrent.Future; import java.util.concurrent.FutureTask; +import java.util.concurrent.ScheduledExecutorService; +import java.util.concurrent.TimeUnit; import java.util.function.Consumer; import javafx.application.Platform; @@ -25,7 +27,8 @@ public class DefaultTaskExecutor implements TaskExecutor { private static final Logger LOGGER = LoggerFactory.getLogger(DefaultTaskExecutor.class); - private static final ExecutorService EXECUTOR = Executors.newFixedThreadPool(5); + private final ExecutorService executor = Executors.newFixedThreadPool(5); + private final ScheduledExecutorService scheduledExecutor = Executors.newScheduledThreadPool(2); /** * @@ -95,13 +98,19 @@ public Future execute(BackgroundTask task) { @Override public Future execute(Task task) { - EXECUTOR.submit(task); + executor.submit(task); return task; } + @Override + public Future schedule(BackgroundTask task, long delay, TimeUnit unit) { + return scheduledExecutor.schedule(getJavaFXTask(task), delay, unit); + } + @Override public void shutdown() { - EXECUTOR.shutdownNow(); + executor.shutdownNow(); + scheduledExecutor.shutdownNow(); } private Task getJavaFXTask(BackgroundTask task) { diff --git a/src/main/java/org/jabref/gui/util/TaskExecutor.java b/src/main/java/org/jabref/gui/util/TaskExecutor.java index 0d5f2f8c8f3..ec09e993f99 100644 --- a/src/main/java/org/jabref/gui/util/TaskExecutor.java +++ b/src/main/java/org/jabref/gui/util/TaskExecutor.java @@ -1,6 +1,7 @@ package org.jabref.gui.util; import java.util.concurrent.Future; +import java.util.concurrent.TimeUnit; import javafx.concurrent.Task; @@ -29,6 +30,18 @@ public interface TaskExecutor { */ Future execute(Task task); + /** + * Submits a one-shot task that becomes enabled after the given delay. + * + * @param task the task to execute + * @param delay the time from now to delay execution + * @param unit the time unit of the delay parameter + * @return a ScheduledFuture representing pending completion of + * the task and whose {@code get()} method will return + * {@code null} upon completion + */ + Future schedule(BackgroundTask task, long delay, TimeUnit unit); + /** * Shutdown the task executor. */