加入收藏 | 设为首页 | 会员中心 | 我要投稿 威海站长网 (https://www.0631zz.com/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 运营中心 > 网站设计 > 教程 > 正文

宜人贷蜂巢API网关技术解密之Netty使用实践

发布时间:2019-04-27 15:22:34 所属栏目:教程 来源:蜂巢团队
导读:宜人贷蜂巢团队,由Michael创立于2013年,通过使用互联网科技手段助力金融生态和谐健康发展。自成立起一直致力于多维度数据闭环平台建设。目前团队规模超过百人,涵盖征信、电商、金融、社交、五险一金和保险等用户授信数据的抓取解析业务,辅以先进的数据

DefaultEventExecutorChooserFactory根据线程数创建具体的EventExecutorChooser,线程数如果等于2^n,可使用按位与替代取模运算,节省cpu的计算资源,见源码:

  1. @SuppressWarnings("unchecked")  
  2. @Override  
  3. public EventExecutorChooser newChooser(EventExecutor[] executors) {  
  4.     if (isPowerOfTwo(executors.length)) {  
  5.         return new PowerOfTowEventExecutorChooser(executors);  
  6.     } else {  
  7.         return new GenericEventExecutorChooser(executors);  
  8.     }  
  9. }   
  10.     private static final class PowerOfTowEventExecutorChooser implements EventExecutorChooser {  
  11.         private final AtomicInteger idx = new AtomicInteger();  
  12.         private final EventExecutor[] executors;   
  13.  
  14.         PowerOfTowEventExecutorChooser(EventExecutor[] executors) {  
  15.             this.executors = executors;  
  16.         }   
  17.  
  18.         @Override  
  19.         public EventExecutor next() {  
  20.             return executors[idx.getAndIncrement() & executors.length - 1];  
  21.         }  
  22.     }   
  23.  
  24.     private static final class GenericEventExecutorChooser implements EventExecutorChooser {  
  25.         private final AtomicInteger idx = new AtomicInteger();  
  26.         private final EventExecutor[] executors;   
  27.  
  28.         GenericEventExecutorChooser(EventExecutor[] executors) {  
  29.             this.executors = executors;  
  30.         }   
  31.  
  32.         @Override  
  33.         public EventExecutor next() {  
  34.             return executors[Math.abs(idx.getAndIncrement() % executors.length)];  
  35.         }  
  36.     } 

newChild(executor, args)的创建细节,见下:

(编辑:威海站长网)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

热点阅读