/** * 在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; } }