mirror of
https://github.com/dromara/RuoYi-Vue-Plus.git
synced 2026-02-04 13:36:02 +08:00
update 优化 增加线程工具简化虚拟线程语法
This commit is contained in:
@@ -33,8 +33,6 @@ import org.springframework.stereotype.Service;
|
||||
|
||||
import java.time.Duration;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
/**
|
||||
@@ -151,22 +149,17 @@ public class SysLoginService {
|
||||
loginUser.setDeptName(deptOpt.map(SysDeptVo::getDeptName).orElse(StringUtils.EMPTY));
|
||||
loginUser.setDeptCategory(deptOpt.map(SysDeptVo::getDeptCategory).orElse(StringUtils.EMPTY));
|
||||
}
|
||||
try (ExecutorService executor = Executors.newVirtualThreadPerTaskExecutor()) {
|
||||
executor.execute(() -> {
|
||||
loginUser.setMenuPermission(permissionService.getMenuPermission(userId));
|
||||
});
|
||||
executor.execute(() -> {
|
||||
loginUser.setRolePermission(permissionService.getRolePermission(userId));
|
||||
});
|
||||
executor.execute(() -> {
|
||||
List<SysRoleVo> roles = roleService.selectRolesByUserId(userId);
|
||||
loginUser.setRoles(BeanUtil.copyToList(roles, RoleDTO.class));
|
||||
});
|
||||
executor.execute(() -> {
|
||||
List<SysPostVo> posts = postService.selectPostsByUserId(userId);
|
||||
loginUser.setPosts(BeanUtil.copyToList(posts, PostDTO.class));
|
||||
});
|
||||
}
|
||||
ThreadUtils.virtualSubmit(() -> {
|
||||
loginUser.setMenuPermission(permissionService.getMenuPermission(userId));
|
||||
}, () -> {
|
||||
loginUser.setRolePermission(permissionService.getRolePermission(userId));
|
||||
}, () -> {
|
||||
List<SysRoleVo> roles = roleService.selectRolesByUserId(userId);
|
||||
loginUser.setRoles(BeanUtil.copyToList(roles, RoleDTO.class));
|
||||
}, () -> {
|
||||
List<SysPostVo> posts = postService.selectPostsByUserId(userId);
|
||||
loginUser.setPosts(BeanUtil.copyToList(posts, PostDTO.class));
|
||||
});
|
||||
return loginUser;
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
package org.dromara.common.core.utils;
|
||||
|
||||
import lombok.AccessLevel;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.*;
|
||||
|
||||
/**
|
||||
* 线程工具
|
||||
*
|
||||
* @author Lion Li
|
||||
*/
|
||||
@NoArgsConstructor(access = AccessLevel.PRIVATE)
|
||||
public class ThreadUtils {
|
||||
|
||||
/**
|
||||
* 批量执行任务
|
||||
*/
|
||||
public static void virtualSubmit(Runnable ...runnableList) {
|
||||
List<Future<?>> callableList = new ArrayList<>();
|
||||
try (ExecutorService executor = Executors.newVirtualThreadPerTaskExecutor()) {
|
||||
for (Runnable runnable : runnableList) {
|
||||
callableList.add(executor.submit(runnable));
|
||||
}
|
||||
for (Future<?> future : callableList) {
|
||||
future.get();
|
||||
}
|
||||
} catch (InterruptedException | ExecutionException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user