huangyiminghappy opened a new issue #2306:
URL: https://github.com/apache/rocketmq/issues/2306


   n the org.apache.rocketmq.remoting.common.RemotingUtil.openSelector
   `public static Selector openSelector() throws IOException {
       Selector result = null;
   
       if (isLinuxPlatform()) {
           try {
               final Class<?> providerClazz = 
Class.forName("sun.nio.ch.EPollSelectorProvider");
               if (providerClazz != null) {
                   try {
                       final Method method = 
providerClazz.getMethod("provider");
                       if (method != null) {
                           final SelectorProvider selectorProvider = 
(SelectorProvider) method.invoke(null);
                           if (selectorProvider != null) {
                               result = selectorProvider.openSelector();
                           }
                       }
                   } catch (final Exception e) {
                       log.warn("Open ePoll Selector for linux platform 
exception", e);
                   }
               }
           } catch (final Exception e) {
               // ignore
           }
       }
   
       if (result == null) {
           result = Selector.open();
       }
   
       return result;
   }`
   
   get the Selector don't need to judge by programming,because the code 
`Selector.open()`
   has the ability to choose Selector according to the platform.
   
   Example in my macos's jdk 8,the Selector.open ,the code is `
   public static Selector open() throws IOException { 
      return SelectorProvider.provider().openSelector();
    }
    
   public static SelectorProvider provider() {
       synchronized (lock) {
           if (provider != null)
               return provider;
           return AccessController.doPrivileged(
               new PrivilegedAction<SelectorProvider>() {
                   public SelectorProvider run() {
                           if (loadProviderFromProperty())
                               return provider;
                           if (loadProviderAsService())
                               return provider;
                           provider = 
sun.nio.ch.DefaultSelectorProvider.create();
                           return provider;
                       }
                   });
       }
   }
   `
   
    
   the code `provider = sun.nio.ch.DefaultSelectorProvider.create();`
   
   
   it's implementation is different depending on the platform,and if it is 
openjdk,get Selector is the 
same,link:https://github.com/ibmruntimes/openj9-openjdk-jdk8/blob/c85b84056711e44d349a1d967eca1e7ace723566/jdk/src/solaris/classes/sun/nio/ch/DefaultSelectorProvider.java
   
    


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to