public RFuture<Void> unlockAsync(long threadId){ RPromise<Void> result = new RedissonPromise<>(); // 实际解锁操作 RFuture<Boolean> future = unlockInnerAsync(threadId);
future.onComplete((opStatus, e) -> { // 解锁完成后取消续约,这部分逻辑参考之前的解锁源码部分 cancelExpirationRenewal(threadId); if (e != null) { result.tryFailure(e); return; }
if (opStatus == null) { IllegalMonitorStateException cause = new IllegalMonitorStateException("attempt to unlock lock, not locked by current thread by node id: " + id + " thread-id: " + threadId); result.tryFailure(cause); return; }
Abstract DataSource implementation that routes getConnection() calls to one of various target DataSources based on a lookup key. The latter is usually (but not necessarily) determined through some thread-bound transaction context.
// Initialize the system class. Called after thread initialization. privatestaticvoidinitializeSystemClass(){ ... // 对于程序 挂断、终止、中断的处理 // Setup Java signal handlers for HUP, TERM, and INT (where available). Terminator.setup(); ... }
// 由Runtime.exit()触发调用 staticvoidexit(int status){ ... synchronized (Shutdown.class) { /* Synchronize on the class object, causing any other thread * that attempts to initiate shutdown to stall indefinitely */ beforeHalt(); sequence(); halt(status); } }
// 容器关闭 @Override publicvoidclose(){ synchronized (this.startupShutdownMonitor) { doClose(); // 移除shutdown hook if (this.shutdownHook != null) { try { Runtime.getRuntime().removeShutdownHook(this.shutdownHook); } catch (IllegalStateException ex) { // ignore - VM is already shutting down } } } }
// 实际关闭容器的方法 protectedvoiddoClose(){ // Check whether an actual close attempt is necessary... if (this.active.get() && this.closed.compareAndSet(false, true)) { ...
@Override publicbooleansupports(MethodParameter returnType, Class converterType){ // 如果方法上有@MyResponse注解,返回false,不需要设置统一响应结果 if (returnType.hasMethodAnnotation(MyResponse.class)) { returnfalse; }
returntrue; }
在UserController中创建一个带有@MyResponse注解的请求
UserController.java
1 2 3 4 5 6 7 8 9 10
@MyResponse @GetMapping(value = "/mock") public UserDO mockUser(){ UserDO user = new UserDO(); user.setUsername("july"); user.setMobilePhone("18756989090"); user.setUserState(0);