调整格式

pull/652/head
dante 2021-06-27 00:14:38 +08:00
parent b1a3064cc8
commit 721bbe2cbc
1 changed files with 38 additions and 34 deletions

View File

@ -57,6 +57,7 @@ public class UserDetailsServiceImpl implements UserDetailsService {
final static Map<String, Future<JwtUserDto>> userDtoCache = new ConcurrentHashMap<>();
public static ExecutorService executor = newThreadPool();
@Override
public JwtUserDto loadUserByUsername(String username) {
JwtUserDto jwtUserDto = null;
@ -84,17 +85,7 @@ public class UserDetailsServiceImpl implements UserDetailsService {
return jwtUserDto;
}
if (future!=null) {
try {
jwtUserDto=future.get();
}catch (InterruptedException | ExecutionException e) {
throw new RuntimeException(e.getMessage());
}
// 检查dataScope是否修改
List<Long> dataScopes = jwtUserDto.getDataScopes();
dataScopes.clear();
dataScopes.addAll(dataService.getDeptIds(jwtUserDto.getUser()));
}else{
if (future==null) {
Callable<JwtUserDto> call=()->getJwtBySearchDB(username);
FutureTask<JwtUserDto> ft=new FutureTask<>(call);
future=userDtoCache.putIfAbsent(username,ft);
@ -109,10 +100,23 @@ public class UserDetailsServiceImpl implements UserDetailsService {
}catch (InterruptedException | ExecutionException e) {
throw new RuntimeException(e.getMessage());
}
}else{
try {
jwtUserDto=future.get();
}catch (InterruptedException | ExecutionException e) {
throw new RuntimeException(e.getMessage());
}
// 检查dataScope是否修改
List<Long> dataScopes = jwtUserDto.getDataScopes();
dataScopes.clear();
dataScopes.addAll(dataService.getDeptIds(jwtUserDto.getUser()));
}
return jwtUserDto;
}
private JwtUserDto getJwtBySearchDB(String username) {
UserDto user;
try {
@ -153,7 +157,7 @@ public class UserDetailsServiceImpl implements UserDetailsService {
return thread;
}
};
return new ThreadPoolExecutor(8, 200,
return new ThreadPoolExecutor(10, 200,
0L, TimeUnit.MILLISECONDS,
new LinkedBlockingQueue<>(1024),
namedThreadFactory,