Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Optimized RpcMessageHandler to reduce thread pool usage
  • Loading branch information
zrlw committed Feb 20, 2025
commit 00ece645d0b321e01789f4b458508230df9bf761
Original file line number Diff line number Diff line change
Expand Up @@ -18,26 +18,32 @@

import org.apache.dubbo.common.bytecode.NoSuchMethodException;
import org.apache.dubbo.common.bytecode.Wrapper;
import org.apache.dubbo.common.utils.ConcurrentHashMapUtils;
import org.apache.dubbo.remoting.RemotingException;
import org.apache.dubbo.remoting.exchange.ExchangeChannel;
import org.apache.dubbo.remoting.exchange.support.Replier;

import java.lang.reflect.InvocationTargetException;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;

/**
* RpcMessageHandler.
*/
public class RpcMessageHandler implements Replier<RpcMessage> {
private static final ConcurrentMap<String, Object> IMPLEMENT_MAP = new ConcurrentHashMap<>();
private static final ServiceProvider DEFAULT_PROVIDER = new ServiceProvider() {
public Object getImplementation(String service) {
String impl = service + "Impl";
try {
Class<?> cl = Thread.currentThread().getContextClassLoader().loadClass(impl);
return cl.getDeclaredConstructor().newInstance();
} catch (Exception e) {
e.printStackTrace();
}
return null;
return ConcurrentHashMapUtils.computeIfAbsent(IMPLEMENT_MAP, impl, (s) -> {
try {
Class<?> cl = Thread.currentThread().getContextClassLoader().loadClass(s);
return cl.getDeclaredConstructor().newInstance();
} catch (Exception e) {
e.printStackTrace();
}
return null;
});
}
};
private ServiceProvider mProvider;
Expand Down