File tree Expand file tree Collapse file tree 1 file changed +13
-7
lines changed
dubbo-remoting/dubbo-remoting-netty4/src/test/java/org/apache/dubbo/remoting/transport/netty4 Expand file tree Collapse file tree 1 file changed +13
-7
lines changed Original file line number Diff line number Diff line change 1818
1919import org .apache .dubbo .common .bytecode .NoSuchMethodException ;
2020import org .apache .dubbo .common .bytecode .Wrapper ;
21+ import org .apache .dubbo .common .utils .ConcurrentHashMapUtils ;
2122import org .apache .dubbo .remoting .RemotingException ;
2223import org .apache .dubbo .remoting .exchange .ExchangeChannel ;
2324import org .apache .dubbo .remoting .exchange .support .Replier ;
2425
2526import java .lang .reflect .InvocationTargetException ;
27+ import java .util .concurrent .ConcurrentHashMap ;
28+ import java .util .concurrent .ConcurrentMap ;
2629
2730/**
2831 * RpcMessageHandler.
2932 */
3033public class RpcMessageHandler implements Replier <RpcMessage > {
34+ private static final ConcurrentMap <String , Object > IMPLEMENT_MAP = new ConcurrentHashMap <>();
3135 private static final ServiceProvider DEFAULT_PROVIDER = new ServiceProvider () {
3236 public Object getImplementation (String service ) {
3337 String impl = service + "Impl" ;
34- try {
35- Class <?> cl = Thread .currentThread ().getContextClassLoader ().loadClass (impl );
36- return cl .getDeclaredConstructor ().newInstance ();
37- } catch (Exception e ) {
38- e .printStackTrace ();
39- }
40- return null ;
38+ return ConcurrentHashMapUtils .computeIfAbsent (IMPLEMENT_MAP , impl , (s ) -> {
39+ try {
40+ Class <?> cl = Thread .currentThread ().getContextClassLoader ().loadClass (s );
41+ return cl .getDeclaredConstructor ().newInstance ();
42+ } catch (Exception e ) {
43+ e .printStackTrace ();
44+ }
45+ return null ;
46+ });
4147 }
4248 };
4349 private ServiceProvider mProvider ;
You can’t perform that action at this time.
0 commit comments