Browse Source
Merge in DESIGN/design from ~DESTINY.LIN/design:fix-lag to fix-lag * commit 'a1ef183761e2191b5d9ab68d72181f5050975fb2': REPORT-111337 【设计器性能】设计器卡顿优化 打开模板动画优化 REPORT-111337 【设计器性能】设计器卡顿优化 打开模板动画优化 REPORT-111337 【设计器性能】设计器卡顿优化 打开模板动画优化fix-lag
Destiny.Lin-林锦龙
11 months ago
5 changed files with 164 additions and 10 deletions
@ -0,0 +1,66 @@
|
||||
package com.fr.design.worker.check; |
||||
|
||||
import com.fr.log.FineLoggerFactory; |
||||
|
||||
import javax.swing.SwingWorker; |
||||
import java.util.concurrent.Callable; |
||||
import java.util.concurrent.TimeUnit; |
||||
import java.util.concurrent.TimeoutException; |
||||
|
||||
/** |
||||
* 检查的Worker |
||||
* |
||||
* @author Destiny.Lin |
||||
* @since 11.0 |
||||
* Created on 2024/1/8 |
||||
*/ |
||||
public abstract class BaseCheckLockWorker extends SwingWorker<CheckLockResult, Void> { |
||||
|
||||
private static final int TIME_OUT = 50; |
||||
private boolean slowly = false; |
||||
private final Callable<CheckLockResult> doInBackground; |
||||
private CheckLockResult result; |
||||
|
||||
public BaseCheckLockWorker(Callable<CheckLockResult> doInBackground) { |
||||
this.doInBackground = doInBackground; |
||||
} |
||||
@Override |
||||
protected CheckLockResult doInBackground() throws Exception { |
||||
return this.doInBackground.call(); |
||||
} |
||||
|
||||
@Override |
||||
protected void done() { |
||||
try { |
||||
result = get(); |
||||
if (slowly) { |
||||
dealResultWhenSlowly(result); |
||||
} |
||||
} catch (Exception e) { |
||||
throw new RuntimeException(e); |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* 获取结果 |
||||
*/ |
||||
public CheckLockResult getResult() { |
||||
if (result != null) { |
||||
return result; |
||||
} |
||||
try { |
||||
return this.get(TIME_OUT, TimeUnit.MILLISECONDS); |
||||
} catch (TimeoutException e) { |
||||
slowly = true; |
||||
} catch (Exception exception) { |
||||
FineLoggerFactory.getLogger().error(exception.getMessage(), exception); |
||||
} |
||||
return null; |
||||
} |
||||
|
||||
|
||||
/** |
||||
* 如果获取结果超过TIME_OUT,则通过这个方式处理后续 |
||||
*/ |
||||
public abstract void dealResultWhenSlowly(CheckLockResult result); |
||||
} |
@ -0,0 +1,30 @@
|
||||
package com.fr.design.worker.check; |
||||
|
||||
import com.fr.workspace.base.UserInfo; |
||||
|
||||
/** |
||||
* 信息检查结果 |
||||
* |
||||
* @author Destiny.Lin |
||||
* @since 11.0 |
||||
* Created on 2024/1/8 |
||||
*/ |
||||
public class CheckLockResult { |
||||
|
||||
private boolean lock = false; |
||||
private UserInfo userInfo; |
||||
|
||||
|
||||
public CheckLockResult(boolean lock, UserInfo userInfo) { |
||||
this.lock = lock; |
||||
this.userInfo = userInfo; |
||||
} |
||||
|
||||
public boolean isLock() { |
||||
return lock; |
||||
} |
||||
|
||||
public UserInfo getUserInfo() { |
||||
return userInfo; |
||||
} |
||||
} |
Loading…
Reference in new issue