Browse Source

REPORT-83197【设计器】启动页性能优化

将异步功能放到 UIUtil 中去执行。避免多线程问题
feature/x
Harrison 2 years ago
parent
commit
0f33a0fee9
  1. 36
      designer-base/src/main/java/com/fr/design/actions/core/ActionFactory.java
  2. 29
      designer-base/src/main/java/com/fr/startup/ui/StartupLoadingPanel.java

36
designer-base/src/main/java/com/fr/design/actions/core/ActionFactory.java

@ -6,12 +6,10 @@ import com.fr.design.file.HistoryTemplateListPane;
import com.fr.design.mainframe.JTemplate; import com.fr.design.mainframe.JTemplate;
import com.fr.design.menu.MenuKeySet; import com.fr.design.menu.MenuKeySet;
import com.fr.design.selection.QuickEditor; import com.fr.design.selection.QuickEditor;
import com.fr.design.ui.util.UIUtil;
import com.fr.log.FineLoggerFactory; import com.fr.log.FineLoggerFactory;
import com.fr.stable.StringUtils; import com.fr.stable.StringUtils;
import com.fr.start.common.DesignerStartupPool; import com.fr.start.common.DesignerStartupPool;
import com.fr.third.guava.util.concurrent.FutureCallback;
import com.fr.third.guava.util.concurrent.Futures;
import com.fr.third.guava.util.concurrent.ListenableFutureTask;
import javax.swing.Action; import javax.swing.Action;
import javax.swing.KeyStroke; import javax.swing.KeyStroke;
@ -22,7 +20,7 @@ import java.util.Arrays;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
import java.util.concurrent.Callable; import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap; import java.util.concurrent.ConcurrentMap;
import java.util.concurrent.CopyOnWriteArraySet; import java.util.concurrent.CopyOnWriteArraySet;
@ -86,23 +84,19 @@ public class ActionFactory {
public static void registerAsyncInitCellEditorClass(Class keyClazz, Class<? extends QuickEditor> editorClazz) { public static void registerAsyncInitCellEditorClass(Class keyClazz, Class<? extends QuickEditor> editorClazz) {
cellEditorClass.put(keyClazz, editorClazz); cellEditorClass.put(keyClazz, editorClazz);
Callable<QuickEditor> callable = new Callable<QuickEditor>() { CompletableFuture.runAsync(() -> {
@Override UIUtil.invokeAndWaitIfNeeded(new Runnable() {
public QuickEditor call() throws Exception { @Override
return editorClazz.newInstance(); public void run() {
} try {
}; QuickEditor quickEditor = editorClazz.newInstance();
ListenableFutureTask<QuickEditor> future = ListenableFutureTask.create(callable); cellEditorClass.remove(keyClazz);
Futures.addCallback(future, new FutureCallback<QuickEditor>() { cellEditor.put(keyClazz, quickEditor);
@Override } catch (Exception e) {
public void onSuccess(QuickEditor quickEditor) { FineLoggerFactory.getLogger().error(e.getMessage(), e);
cellEditorClass.remove(keyClazz); }
cellEditor.put(keyClazz, quickEditor); }
} });
@Override
public void onFailure(Throwable throwable) {
}
}, DesignerStartupPool.designer()); }, DesignerStartupPool.designer());
} }

29
designer-base/src/main/java/com/fr/startup/ui/StartupLoadingPanel.java

@ -4,7 +4,7 @@ import com.fr.concurrent.FineExecutors;
import com.fr.concurrent.NamedThreadFactory; import com.fr.concurrent.NamedThreadFactory;
import com.fr.design.gui.iprogressbar.ProgressDialog; import com.fr.design.gui.iprogressbar.ProgressDialog;
import com.fr.design.i18n.Toolkit; import com.fr.design.i18n.Toolkit;
import com.fr.design.mainframe.DesignerContext; import com.fr.design.ui.util.UIUtil;
import com.fr.event.Event; import com.fr.event.Event;
import com.fr.event.EventDispatcher; import com.fr.event.EventDispatcher;
import com.fr.event.Listener; import com.fr.event.Listener;
@ -68,19 +68,20 @@ public class StartupLoadingPanel {
scheduler.scheduleAtFixedRate(new Runnable() { scheduler.scheduleAtFixedRate(new Runnable() {
@Override @Override
public void run() { public void run() {
if (isComplete()) { UIUtil.invokeAndWaitIfNeeded(() -> {
scheduler.shutdown(); if (isComplete()) {
progressDialog.dispose(); scheduler.shutdown();
resetListeners(); progressDialog.dispose();
return; resetListeners();
} return;
if (!progressDialog.isVisible()) { }
progressDialog = new ProgressDialog(DesignerContext.getDesignerFrame()); if (!progressDialog.isVisible()) {
progressDialog.setVisible(true); progressDialog.setVisible(true);
String moduleId = getModuleId(); String moduleId = getModuleId();
progressDialog.updateLoadingText(moduleId); progressDialog.updateLoadingText(moduleId);
} }
progressDialog.setProgressValue(incrementProgress()); progressDialog.setProgressValue(incrementProgress());
});
} }
}, 0, STEP_HEARTBEAT, TimeUnit.MILLISECONDS); }, 0, STEP_HEARTBEAT, TimeUnit.MILLISECONDS);

Loading…
Cancel
Save