From 4c051b8291000d37952733f16d0ab36ccfe7c3c5 Mon Sep 17 00:00:00 2001 From: songxinjianqwe Date: Fri, 24 Aug 2018 11:33:53 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BB=A3=E7=A0=81=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../toy/common/context/RPCThreadLocalContext.java | 8 ++++---- .../toy/common/context/RPCThreadSharedContext.java | 14 +++++++------- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/toy-rpc-core/src/main/java/com/sinjinsong/toy/common/context/RPCThreadLocalContext.java b/toy-rpc-core/src/main/java/com/sinjinsong/toy/common/context/RPCThreadLocalContext.java index 032594e..442ea40 100644 --- a/toy-rpc-core/src/main/java/com/sinjinsong/toy/common/context/RPCThreadLocalContext.java +++ b/toy-rpc-core/src/main/java/com/sinjinsong/toy/common/context/RPCThreadLocalContext.java @@ -9,7 +9,7 @@ * @date 2018/6/10 * 线程私有! */ -public class RPCThreadLocalContext { +public class RPCThreadLocalContext { private static final ThreadLocal RPC_CONTEXT = new ThreadLocal() { @Override protected Object initialValue() { @@ -20,7 +20,7 @@ protected Object initialValue() { private RPCThreadLocalContext() { } - private Future future; + private Future future; private Invoker invoker; @@ -28,7 +28,7 @@ public static RPCThreadLocalContext getContext() { return RPC_CONTEXT.get(); } - public Future getFuture() { + public Future getFuture() { return future; } @@ -40,7 +40,7 @@ public void setInvoker(Invoker invoker) { this.invoker = invoker; } - public void setFuture(Future future) { + public void setFuture(Future future) { this.future = future; } diff --git a/toy-rpc-core/src/main/java/com/sinjinsong/toy/common/context/RPCThreadSharedContext.java b/toy-rpc-core/src/main/java/com/sinjinsong/toy/common/context/RPCThreadSharedContext.java index 8167c39..585c8d3 100644 --- a/toy-rpc-core/src/main/java/com/sinjinsong/toy/common/context/RPCThreadSharedContext.java +++ b/toy-rpc-core/src/main/java/com/sinjinsong/toy/common/context/RPCThreadSharedContext.java @@ -11,14 +11,14 @@ /** * @author sinjinsong * @date 2018/6/10 - * * 线程共享 + * 不可以使用ThreadLocal来存放,因为发出请求的线程(如main)和接受响应的线程(某个eventloop)不能保证是同一个线程 */ @Slf4j public class RPCThreadSharedContext { private static final ConcurrentHashMap> RESPONSES = new ConcurrentHashMap<>(); - private static final ConcurrentHashMap> HANDLER_MAP = new ConcurrentHashMap<>(); - + private static final ConcurrentHashMap> HANDLER_MAP = new ConcurrentHashMap<>(); + public static void registerResponseFuture(String requestId, CompletableFuture future) { RESPONSES.put(requestId, future); } @@ -26,13 +26,13 @@ public static void registerResponseFuture(String requestId, CompletableFuture getAndRemoveResponseFuture(String requestId) { return RESPONSES.remove(requestId); } - - public static void registerHandler(String name,ServiceConfig serviceConfig) { + + public static void registerHandler(String name, ServiceConfig serviceConfig) { HANDLER_MAP.put(name, serviceConfig); } - + public static ServiceConfig getAndRemoveHandler(String name) { - return HANDLER_MAP.remove(name); + return HANDLER_MAP.remove(name); } }