| 
                         监控线程-Monitor为了计算每分钟导入Elasticsearch的数据总条数,利用监控线程,可以调整线程池的线程数的大小,以便利用多线程更快速的导入数据。 
- public void monitorToES() { 
 -  new Thread(() -> { 
 -  while (true) { 
 -  StringBuilder sb = new StringBuilder(); 
 -  sb.append("已办表数::").append(Const.TBL.TBL_PEND_COUNT) 
 -  .append("::已办总数::").append(Const.COUNTER.LD_P_TOTAL) 
 -  .append("::已办入库总数::").append(Const.COUNTER.LD_P); 
 -  sb.append("~~~~已阅表数::").append(Const.TBL.TBL_READ_COUNT); 
 -  sb.append("::已阅总数::").append(Const.COUNTER.LD_R_TOTAL) 
 -  .append("::已阅入库总数::").append(Const.COUNTER.LD_R); 
 -  if (ldPrevPendCount == 0 && ldPrevReadCount == 0) { 
 -  ldPrevPendCount = Const.COUNTER.LD_P.get(); 
 -  ldPrevReadCount = Const.COUNTER.LD_R.get(); 
 -  start = System.currentTimeMillis(); 
 -  } else { 
 -  long end = System.currentTimeMillis(); 
 -  if ((end - start) / 1000 >= 60) { 
 -  start = end; 
 -  sb.append("n#########################################n"); 
 -  sb.append("已办每分钟TPS::" + (Const.COUNTER.LD_P.get() - ldPrevPendCount) + "条"); 
 -  sb.append("::已阅每分钟TPS::" + (Const.COUNTER.LD_R.get() - ldPrevReadCount) + "条"); 
 -  ldPrevPendCount = Const.COUNTER.LD_P.get(); 
 -  ldPrevReadCount = Const.COUNTER.LD_R.get(); 
 -  } 
 -  } 
 -  System.out.println(sb.toString()); 
 -  try { 
 -  Thread.sleep(3000); 
 -  } catch (InterruptedException e) { 
 -  e.printStackTrace(); 
 -  } 
 -  } 
 -  }).start(); 
 - } 
 
  
初始化Elasticsearch:EsClient 
- String cName = meta.get("cName");//es集群名字 
 - String esNodes = meta.get("esNodes");//es集群ip节点 
 - Settings esSetting = Settings.builder() 
 -  .put("cluster.name", cName) 
 -  .put("client.transport.sniff", true)//增加嗅探机制,找到ES集群 
 -  .put("thread_pool.search.size", 5)//增加线程池个数,暂时设为5 
 -  .build(); 
 - String[] nodes = esNodes.split(","); 
 - client = new PreBuiltTransportClient(esSetting); 
 - for (String node : nodes) { 
 -  if (node.length() > 0) { 
 -  String[] hostPort = node.split(":"); 
 -  client.addTransportAddress(new TransportAddress(InetAddress.getByName(hostPort[0]), Integer.parseInt(hostPort[1]))); 
 -  } 
 - } 
 
  
初始化数据库连接 
- conn = DriverManager.getConnection(url, user, password); 
 
                          (编辑:泰州站长网) 
【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! 
                     |