|
@@ -41,7 +41,6 @@ import org.springframework.web.context.request.ServletRequestAttributes;
|
|
|
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
import java.util.*;
|
|
|
-import java.util.concurrent.CompletableFuture;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
@@ -74,20 +73,16 @@ public class SubSyncBusiness implements ISubSyncBusiness {
|
|
|
|
|
|
@Override
|
|
|
public ResponseStatus userSync() {
|
|
|
- CompletableFuture.supplyAsync(()-> {
|
|
|
- getUserInfoFromRemote(1, subSyncConfig.getPageSize());
|
|
|
- return true;
|
|
|
- }).exceptionally(e->{
|
|
|
- log.error("getUserInfoFromRemote error.",e);
|
|
|
- return false;
|
|
|
- }).thenAccept((result)-> {
|
|
|
- if(result) {
|
|
|
- this.userInfoSync();
|
|
|
- }
|
|
|
- }).exceptionally(e->{
|
|
|
- log.error("user sync error.",e);
|
|
|
- return null;
|
|
|
- });
|
|
|
+ //开启父子线程
|
|
|
+ //方法内部有从ThreadLocal获取信息
|
|
|
+ //CompletableFuture默认使用ForkJoin线程池,不要使用1.8的新线程开启方法
|
|
|
+ //也不要使用线程池调用
|
|
|
+ Runnable r = ()->{
|
|
|
+ getUserInfoFromRemote(1, subSyncConfig.getPageSize());
|
|
|
+ userInfoSync();
|
|
|
+ };
|
|
|
+ Thread t = new Thread(r);
|
|
|
+ t.start();
|
|
|
return ResponseStatus.success();
|
|
|
}
|
|
|
|
|
@@ -209,28 +204,17 @@ public class SubSyncBusiness implements ISubSyncBusiness {
|
|
|
|
|
|
@Override
|
|
|
public ResponseStatus orgSync() {
|
|
|
- CompletableFuture.supplyAsync(()-> {
|
|
|
- getOrgInfoFromRemote(1, subSyncConfig.getPageSize());
|
|
|
- return true;
|
|
|
- }).exceptionally(e->{
|
|
|
- log.error("getOrgInfoFromRemote error.",e);
|
|
|
- return false;
|
|
|
- }).thenApply((result)-> {
|
|
|
- if(result) {
|
|
|
- this.orgInfoSync();
|
|
|
- }
|
|
|
- return result;
|
|
|
- }).exceptionally(e->{
|
|
|
- log.error("orgInfoSync error.",e);
|
|
|
- return false;
|
|
|
- }).thenAccept((result)->{
|
|
|
- if(result) {
|
|
|
- this.setPathAndUpId();
|
|
|
- }
|
|
|
- }).exceptionally(e->{
|
|
|
- log.error("setPathAndUpId error.",e);
|
|
|
- return null;
|
|
|
- });
|
|
|
+ //开启父子线程
|
|
|
+ //方法内部有从ThreadLocal获取信息
|
|
|
+ //CompletableFuture默认使用ForkJoin线程池,不要使用1.8的新线程开启方法
|
|
|
+ //也不要使用线程池调用
|
|
|
+ Runnable r = ()->{
|
|
|
+ getOrgInfoFromRemote(1, subSyncConfig.getPageSize());
|
|
|
+ orgInfoSync();
|
|
|
+ setPathAndUpId();
|
|
|
+ };
|
|
|
+ Thread t = new Thread(r);
|
|
|
+ t.start();
|
|
|
return ResponseStatus.success();
|
|
|
}
|
|
|
|