Merge branch 'test' of http://172.16.46.63:30001/gitlab/jygk/dsc into test-dsc
* 'test' of http://172.16.46.63:30001/gitlab/jygk/dsc: feat(gateway): 添加API客户端凭证加密功能支持 优化 1. 移除多余 java 文件 feat:登陆用户的部门数据权限接口增加角色参数
This commit is contained in:
@@ -9,7 +9,7 @@ import java.util.concurrent.*;
|
|||||||
* 多次提交,一次等待
|
* 多次提交,一次等待
|
||||||
*/
|
*/
|
||||||
public class AsyncLatchUtils {
|
public class AsyncLatchUtils {
|
||||||
private static final ThreadLocal<List<TaskInfo>> THREADLOCAL = ThreadLocal.withInitial(LinkedList::new);
|
private static final ThreadLocal<List<TaskInfo>> THREAD_LOCAL = ThreadLocal.withInitial(LinkedList::new);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 提交一个异步任务
|
* 提交一个异步任务
|
||||||
@@ -17,7 +17,7 @@ public class AsyncLatchUtils {
|
|||||||
* @param runnable 需要异步执行的具体业务逻辑
|
* @param runnable 需要异步执行的具体业务逻辑
|
||||||
*/
|
*/
|
||||||
public static void submitTask(Executor executor, Runnable runnable) {
|
public static void submitTask(Executor executor, Runnable runnable) {
|
||||||
THREADLOCAL.get().add(new TaskInfo(executor, runnable));
|
THREAD_LOCAL.get().add(new TaskInfo(executor, runnable));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -25,8 +25,8 @@ public class AsyncLatchUtils {
|
|||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
private static List<TaskInfo> popTask() {
|
private static List<TaskInfo> popTask() {
|
||||||
List<TaskInfo> taskInfos = THREADLOCAL.get();
|
List<TaskInfo> taskInfos = THREAD_LOCAL.get();
|
||||||
THREADLOCAL.remove();
|
THREAD_LOCAL.remove();
|
||||||
return taskInfos;
|
return taskInfos;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -39,7 +39,7 @@ public class AsyncLatchUtils {
|
|||||||
*/
|
*/
|
||||||
public static boolean waitFor(long timeout, TimeUnit timeUnit) {
|
public static boolean waitFor(long timeout, TimeUnit timeUnit) {
|
||||||
List<TaskInfo> taskInfos = popTask();
|
List<TaskInfo> taskInfos = popTask();
|
||||||
if (taskInfos.isEmpty()) {
|
if (taskInfos.isEmpty()) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
CountDownLatch latch = new CountDownLatch(taskInfos.size());
|
CountDownLatch latch = new CountDownLatch(taskInfos.size());
|
||||||
@@ -57,8 +57,11 @@ public class AsyncLatchUtils {
|
|||||||
boolean await = false;
|
boolean await = false;
|
||||||
try {
|
try {
|
||||||
await = latch.await(timeout, timeUnit);
|
await = latch.await(timeout, timeUnit);
|
||||||
} catch (Exception ignored) {}
|
} catch (Exception ignored) {
|
||||||
return await;
|
// 恢复中断状态
|
||||||
|
Thread.currentThread().interrupt();
|
||||||
|
}
|
||||||
|
return await;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final class TaskInfo {
|
private static final class TaskInfo {
|
||||||
|
|||||||
Reference in New Issue
Block a user