Browse Source

REPORT-68726 【迭代】【数据集管理优化】多张模板切换触发搜索,设计器概率卡住

【问题原因】之前的定时器每次搜索都会开始计时,然后新建线程池+线程,在搜索完后停止计时将线程池shutDownNow,是为了不让前一次的搜索计时影响后一次的搜索,但是漏了切换回工具栏的时候停止计时,且每次新建线程池太重了
【改动思路】1.补充切换回工具栏的停止计时逻辑;2.用判断task对象的方式来判断前一次与后一次,保证只有一个线程创建
【review建议】无
feature/x
Yvan 3 years ago
parent
commit
502b4cf58a
  1. 4
      designer-base/src/main/java/com/fr/design/data/datapane/management/search/TableDataTreeSearchManager.java
  2. 2
      designer-base/src/main/java/com/fr/design/data/datapane/management/search/searcher/TableDataTreeSearcher.java
  3. 20
      designer-base/src/main/java/com/fr/design/data/datapane/management/search/time/TableDataSearchTimer.java
  4. 3
      designer-base/src/main/java/com/fr/design/data/datapane/management/search/time/TableDataSearchTimerTask.java

4
designer-base/src/main/java/com/fr/design/data/datapane/management/search/TableDataTreeSearchManager.java

@ -131,7 +131,7 @@ public class TableDataTreeSearchManager {
* @param searchText
*/
public void startSearch(String searchText) {
if (isRepeatSearch(searchText)) {
if (isRepeatSearch(searchText) || StringUtils.isEmpty(searchText)) {
return;
}
setTreeSearchStatus(TreeSearchStatus.SEARCHING);
@ -196,6 +196,7 @@ public class TableDataTreeSearchManager {
*/
public void restoreToolBarAndTreePane() {
setTreeSearchStatus(TreeSearchStatus.NOT_IN_SEARCH_MODE);
TableDataSearchTimer.getInstance().stopClock();
if (treeSearcher != null) {
treeSearcher.afterSearch();
}
@ -210,6 +211,7 @@ public class TableDataTreeSearchManager {
*/
public void restoreTreePane() {
setTreeSearchStatus(TreeSearchStatus.SEARCH_NOT_BEGIN);
TableDataSearchTimer.getInstance().stopClock();
lastSearchText = null;
if (rendererHelper != null) {
rendererHelper.restore(getCurrentTableDataTree());

2
designer-base/src/main/java/com/fr/design/data/datapane/management/search/searcher/TableDataTreeSearcher.java

@ -75,7 +75,7 @@ public class TableDataTreeSearcher implements TreeSearcher {
* @param tableDataSource
*/
public void beforeSearch(TableDataSearchMode searchMode, TableDataSource tableDataSource) {
executorService = Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors(), new NamedThreadFactory(TableDataTreeSearchManager.class));
executorService = Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors(), new NamedThreadFactory(TableDataTreeSearcher.class));
collectTableDataWrappers(searchMode, tableDataSource);
preCalculateColumns();
}

20
designer-base/src/main/java/com/fr/design/data/datapane/management/search/time/TableDataSearchTimer.java

@ -1,6 +1,9 @@
package com.fr.design.data.datapane.management.search.time;
import com.fr.concurrent.NamedThreadFactory;
import com.fr.general.ComparatorUtils;
import com.fr.general.GeneralUtils;
import com.fr.third.org.apache.commons.lang3.ObjectUtils;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
@ -16,7 +19,7 @@ public class TableDataSearchTimer {
/**
* 定时器
*/
private ScheduledExecutorService scheduler;
private static ScheduledExecutorService scheduler = Executors.newSingleThreadScheduledExecutor(new NamedThreadFactory(TableDataSearchTimer.class));
/**
* 定时任务
@ -40,15 +43,24 @@ public class TableDataSearchTimer {
}
public void startClock() {
this.scheduler = Executors.newSingleThreadScheduledExecutor(new NamedThreadFactory(TableDataSearchTimer.class));
this.timeTask = new TableDataSearchTimerTask();
scheduler.schedule(timeTask, MAX_SEARCH_TIME, TimeUnit.MILLISECONDS);
}
public void stopClock() {
this.timeTask = null;
if (this.scheduler != null) {
this.scheduler.shutdownNow();
}
public void shutdown() {
scheduler.shutdown();
}
/**
* 判断是不是当前的Timer中的task为了避免shutdownNow()之后原task仍在执行可能会
* @param task
* @return
*/
public boolean isCurrentTask(TableDataSearchTimerTask task) {
return ComparatorUtils.equals(this.timeTask, task);
}
}

3
designer-base/src/main/java/com/fr/design/data/datapane/management/search/time/TableDataSearchTimerTask.java

@ -14,7 +14,8 @@ public class TableDataSearchTimerTask implements Runnable {
@Override
public void run() {
// 最大单次搜索时间过后,将结束搜索
if (TableDataTreeSearchManager.getInstance().getTreeSearchStatus() == TreeSearchStatus.SEARCHING) {
if (TableDataTreeSearchManager.getInstance().getTreeSearchStatus() == TreeSearchStatus.SEARCHING &&
TableDataSearchTimer.getInstance().isCurrentTask(this)) {
TableDataTreeSearchManager.getInstance().completeSearch();
}
}

Loading…
Cancel
Save