Пример #1
0
 public void run() {
   while (true) {
     try {
       ThEvent event = queue.take(); // 获取并移除此队列的头,如果此队列为空,则返回 null。
       size++;
       process(event);
       long curTime = System.currentTimeMillis();
       if (size == batchSize || ((curTime - lastTime) > batchTime)) {
         int temp = size;
         if (temp > 0) {
           size = 0;
           if (flag) {
             ScheduledExecutorService service = Executors.newScheduledThreadPool(1);
             Runnable hbase = new HbaseStorageTask(hbaseService.getTable(), "event");
             // hbase.run(); // 首次启动初始化缓存
             service.scheduleWithFixedDelay(hbase, 1, 10, TimeUnit.SECONDS);
             flag = false;
           }
         }
         log.info(
             "批量存储驾驶事件数据信息----提交:[{}]条, 耗时:[{}]ms", temp, (System.currentTimeMillis() - lastTime));
         lastTime = System.currentTimeMillis();
       }
     } catch (Exception e) {
       log.error("存储驾驶事件数据异常:" + e.getMessage(), e);
     }
   }
 }
Пример #2
0
 public void process(ThEvent event) throws IOException {
   String rowKey = event.getStartTime() + UUID.randomUUID().toString();
   Put put = new Put(Bytes.toBytes(rowKey));
   put.add(
       Bytes.toBytes("info"),
       Bytes.toBytes(event.getVid()),
       Bytes.toBytes(JSON.toJSONString(event)));
   hbaseService.getTable().put(put);
   count++;
   Cache.getTableMap().put("event", count);
 }