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

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

发布时间:2019-04-25 16:59:06 所属栏目:教程 来源:蜂巢团队
导读:宜人贷蜂巢团队,由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)的建设细节,见下:

(编辑:湖南网)

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

热点阅读