工具类优化

v1.4.1
Parker 4 years ago
parent af0ff46fba
commit 5ac3f2cbe9

@ -64,25 +64,25 @@ public class AsyncProcessorReFuse {
// 关闭事件的挂钩 // 关闭事件的挂钩
Runtime.getRuntime().addShutdownHook(new Thread(() -> { Runtime.getRuntime().addShutdownHook(new Thread(() -> {
log.info("AsyncProcessor shutting down."); log.info("AsyncProcessorReFuse 异步处理器关闭");
EXECUTOR.shutdown(); EXECUTOR.shutdown();
try { try {
// 等待1秒执行关闭 // 等待1秒执行关闭
if (!EXECUTOR.awaitTermination(DEFAULT_WAIT_TIME, TimeUnit.SECONDS)) { if (!EXECUTOR.awaitTermination(DEFAULT_WAIT_TIME, TimeUnit.SECONDS)) {
log.error("AsyncProcessor shutdown immediately due to wait timeout."); log.error("AsyncProcessorReFuse 由于等待超时,异步处理器立即关闭");
EXECUTOR.shutdownNow(); EXECUTOR.shutdownNow();
} }
} catch (InterruptedException e) { } catch (InterruptedException e) {
log.error("AsyncProcessor shutdown interrupted."); log.error("AsyncProcessorReFuse 异步处理器关闭中断");
EXECUTOR.shutdownNow(); EXECUTOR.shutdownNow();
} }
log.info("AsyncProcessor shutdown complete."); log.info("AsyncProcessorReFuse 异步处理器关闭完成");
})); }));
} catch (Exception e) { } catch (Exception e) {
log.error("AsyncProcessor init error.", e); log.error("AsyncProcessorReFuse 异步处理器初始化错误", e);
throw new ExceptionInInitializerError(e); throw new ExceptionInInitializerError(e);
} }
} }
@ -104,7 +104,7 @@ public class AsyncProcessorReFuse {
try { try {
EXECUTOR.execute(task); EXECUTOR.execute(task);
} catch (RejectedExecutionException e) { } catch (RejectedExecutionException e) {
log.error("Task executing was rejected.", e); log.error("AsyncProcessorReFuse 执行任务被拒绝", e);
return false; return false;
} }
return true; return true;
@ -121,8 +121,8 @@ public class AsyncProcessorReFuse {
try { try {
return EXECUTOR.submit(task); return EXECUTOR.submit(task);
} catch (RejectedExecutionException e) { } catch (RejectedExecutionException e) {
log.error("Task executing was rejected.", e); log.error("AsyncProcessorReFuse 执行任务被拒绝", e);
throw new UnsupportedOperationException("Unable to submit the task, rejected.", e); throw new UnsupportedOperationException("AsyncProcessorReFuse 无法提交任务,已被拒绝", e);
} }
} }
} }

@ -64,25 +64,25 @@ public class AsyncProcessorWait {
// 这里不会自动关闭线程, 当线程超过阈值时 抛异常 // 这里不会自动关闭线程, 当线程超过阈值时 抛异常
// 关闭事件的挂钩 // 关闭事件的挂钩
Runtime.getRuntime().addShutdownHook(new Thread(() -> { Runtime.getRuntime().addShutdownHook(new Thread(() -> {
log.info("AsyncProcessor shutting down."); log.info("AsyncProcessorWait 异步处理器关闭");
EXECUTOR.shutdown(); EXECUTOR.shutdown();
try { try {
// 等待1秒执行关闭 // 等待1秒执行关闭
if (!EXECUTOR.awaitTermination(DEFAULT_WAIT_TIME, TimeUnit.SECONDS)) { if (!EXECUTOR.awaitTermination(DEFAULT_WAIT_TIME, TimeUnit.SECONDS)) {
log.error("AsyncProcessor shutdown immediately due to wait timeout."); log.error("AsyncProcessorWait 由于等待超时,异步处理器立即关闭");
EXECUTOR.shutdownNow(); EXECUTOR.shutdownNow();
} }
} catch (InterruptedException e) { } catch (InterruptedException e) {
log.error("AsyncProcessor shutdown interrupted."); log.error("AsyncProcessorWait 异步处理器关闭中断");
EXECUTOR.shutdownNow(); EXECUTOR.shutdownNow();
} }
log.info("AsyncProcessor shutdown complete."); log.info("AsyncProcessorWait 异步处理器关闭完成");
})); }));
} catch (Exception e) { } catch (Exception e) {
log.error("AsyncProcessor init error.", e); log.error("AsyncProcessorWait 异步处理器初始化错误", e);
throw new ExceptionInInitializerError(e); throw new ExceptionInInitializerError(e);
} }
} }
@ -104,7 +104,7 @@ public class AsyncProcessorWait {
try { try {
EXECUTOR.execute(task); EXECUTOR.execute(task);
} catch (RejectedExecutionException e) { } catch (RejectedExecutionException e) {
log.error("Task executing was rejected.", e); log.error("AsyncProcessorWait 执行任务被拒绝", e);
return false; return false;
} }
return true; return true;
@ -121,8 +121,8 @@ public class AsyncProcessorWait {
try { try {
return EXECUTOR.submit(task); return EXECUTOR.submit(task);
} catch (RejectedExecutionException e) { } catch (RejectedExecutionException e) {
log.error("Task executing was rejected.", e); log.error("AsyncProcessorWait 执行任务被拒绝", e);
throw new UnsupportedOperationException("Unable to submit the task, rejected.", e); throw new UnsupportedOperationException("AsyncProcessorWait 无法提交任务,已被拒绝", e);
} }
} }
} }

@ -365,7 +365,7 @@ public class Props {
obj = temp.get(k); obj = temp.get(k);
} else if(obj instanceof LinkedHashMap){ } else if(obj instanceof LinkedHashMap){
//Convert //Convert
obj = ((LinkedHashMap) obj).get(k); obj = Convert.convert(LinkedHashMap.class, obj).get(k);
} }
} }
return obj; return obj;

@ -61,8 +61,8 @@ public final class RateLimiterUtil {
// 获得IP // 获得IP
String clientIpAddress = IPUtil.getClientIpAddress(request); String clientIpAddress = IPUtil.getClientIpAddress(request);
// 获得URI // 获得URI
String clientURI = request.getRequestURI(); String clientUri = request.getRequestURI();
return RateLimiterUtil.enter(clientIpAddress, clientURI); return RateLimiterUtil.enter(clientIpAddress, clientUri);
} }
/** /**
@ -74,8 +74,8 @@ public final class RateLimiterUtil {
// 获得IP // 获得IP
String clientIpAddress = IPUtil.getClientIpAddress(request); String clientIpAddress = IPUtil.getClientIpAddress(request);
// 获得URI // 获得URI
String clientURI = request.getRequestURI(); String clientUri = request.getRequestURI();
return RateLimiterUtil.enter(clientIpAddress, clientURI, dfQps); return RateLimiterUtil.enter(clientIpAddress, clientUri, dfQps);
} }
/** /**

Loading…
Cancel
Save