java NIO
linux平台尽可能使用EPollSelectorProvider
public class RemotingUtil {
private static boolean isLinuxPlatform=false;
public static Selector openSelector() throws IOException {
Selector result=null;
if(isLinuxPlatform()){
try {
final Class<?> providerClazz= Class.forName("sun.nio.ch.EPollSelectorProvider");
if(providerClazz!=null){
final Method method=providerClazz.getMethod("provider");
if(method!=null){
final SelectorProvider selectorProvider=(SelectorProvider)method.invoke(null);
if(selectorProvider!=null){
result=selectorProvider.openSelector();
}
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
if(result==null){
result=Selector.open();
}
return result;
}
public static boolean isLinuxPlatform() {
return isLinuxPlatform;
}
}