Пример #1
0
 public void batchUpdate() {
   if (executing) return;
   synchronized (batchDaoLock) {
     // 数据库不可用,则直接退出批量保存。
     DbState ds = DbMonitor.getInstance().getMonitor(dataSource);
     if (null != ds && !ds.isAvailable()) return;
     if (null != executeThreadName) {
       log.error("BatchDao[key=" + key + "] has already been executed by : " + executeThreadName);
     }
     executeThreadName = Thread.currentThread().getName();
     // 取消保存成功标志判断,以免保存异常后临时保存队列无法清空
     // boolean success = false;
     try {
       executing = true;
       _doBatchUpdate();
       // success = true;
     } catch (CannotGetJdbcConnectionException e) {
       // 数据库连接异常,通知监控模块
       tracer.trace("batch dao1 exception: CannotGetJdbcConnectionException");
       if (null != ds) ds.setAvailable(false);
     } catch (BadSqlGrammarException e) {
       // 语法错误,必须纠正。正确情况下,系统不应该打印此错误信息
       tracer.trace("batch dao1 exception:" + e.getLocalizedMessage(), e);
     } catch (Exception e) {
       tracer.trace("batch dao1 exception:" + e.getLocalizedMessage(), e);
       log.warn("batch dao1 exception:" + e.getLocalizedMessage(), e);
     } finally {
       executing = false;
     }
     executeThreadName = null;
   }
 }
Пример #2
0
 public boolean hasDelayData() {
   DbState ds = DbMonitor.getInstance().getMonitor(dataSource);
   boolean result = System.currentTimeMillis() - lastIoTime >= delay && size() > 0;
   if (null != ds) result = result && ds.isAvailable();
   return result;
 }