Browse Source

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

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

26
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(() -> {
UIUtil.invokeAndWaitIfNeeded(new Runnable() {
@Override @Override
public QuickEditor call() throws Exception { public void run() {
return editorClazz.newInstance(); try {
} QuickEditor quickEditor = editorClazz.newInstance();
};
ListenableFutureTask<QuickEditor> future = ListenableFutureTask.create(callable);
Futures.addCallback(future, new FutureCallback<QuickEditor>() {
@Override
public void onSuccess(QuickEditor quickEditor) {
cellEditorClass.remove(keyClazz); cellEditorClass.remove(keyClazz);
cellEditor.put(keyClazz, quickEditor); cellEditor.put(keyClazz, quickEditor);
} catch (Exception e) {
FineLoggerFactory.getLogger().error(e.getMessage(), e);
} }
@Override
public void onFailure(Throwable throwable) {
} }
});
}, DesignerStartupPool.designer()); }, DesignerStartupPool.designer());
} }

5
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,6 +68,7 @@ public class StartupLoadingPanel {
scheduler.scheduleAtFixedRate(new Runnable() { scheduler.scheduleAtFixedRate(new Runnable() {
@Override @Override
public void run() { public void run() {
UIUtil.invokeAndWaitIfNeeded(() -> {
if (isComplete()) { if (isComplete()) {
scheduler.shutdown(); scheduler.shutdown();
progressDialog.dispose(); progressDialog.dispose();
@ -75,12 +76,12 @@ public class StartupLoadingPanel {
return; return;
} }
if (!progressDialog.isVisible()) { if (!progressDialog.isVisible()) {
progressDialog = new ProgressDialog(DesignerContext.getDesignerFrame());
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