/** * 在jboss启动的时候获取第一次统计时间 * @return date类型,第一次执行的整点时间 */ public static Date getFistStatistDate() { Calendar c = Calendar.getInstance(); int hour = c.get(Calendar.HOUR); int min = c.get(Calendar.MINUTE); //如果当前是23点里面分两种情况 if (hour == 23) { //是整点,返回整点 if (min == 0) { c.set(Calendar.SECOND, 0); return c.getTime(); } //不是整点,返回0点 else { c.set(Calendar.HOUR, hour + 1); c.set(Calendar.MINUTE, 0); c.set(Calendar.SECOND, 0); return c.getTime(); } } //如果当前不是23点,也分两种 else { //如果是其他正点,返回整点 if (min == 0) { c.set(Calendar.SECOND, 0); return c.getTime(); } //否则返回下一个整点 else { c.set(Calendar.HOUR, hour + 1); c.set(Calendar.MINUTE, 0); c.set(Calendar.SECOND, 0); return c.getTime(); } } } /** * 获取下一个统计时间整点时刻,测试通过 * @return */ public static Date getNextStatistDate() { Calendar c = Calendar.getInstance(); int hour = c.get(Calendar.HOUR); c.set(Calendar.HOUR, hour + 1); c.set(Calendar.MINUTE, 0); c.set(Calendar.SECOND, 0); return c.getTime(); } private void beginStatist() throws Exception { try { DmfTransactionDelegate.beginTransaction(); DmfStatistDelegate.statist(); DmfTransactionDelegate.commit(); } catch (Throwable e) { e.printStackTrace(); } } /** * 获取所有统计到得数据 * @throws Exception */ public String printData() throws Exception { String rs = "statis error! please check your code!"; try { DmfTransactionDelegate.beginTransaction(); rs = DmfStatistDelegate.printData(); DmfTransactionDelegate.commit(); } catch (Exception e) { e.printStackTrace(); } return rs; } }