最近开放赌场的项目,好郁闷,程序找不到日志,求求大哥哥解救一下啊,先提前谢谢啦。。问题是这样的: 我启动一个定时程序,在run方法里调用我的方法currToHis(), 然后有可能出现异常了,但是异常信息没有打印,是不是这个线程自动销毁了。
代码: /**
* 2012-03-15
* @param DBparam
* @throws Exception
*/
public void currToHis(String DBparam,int s) {
try {
DBInstance(DBparam).startTransaction(Connection.TRANSACTION_SERIALIZABLE);
DBInstance(DBparam).insert("currtoHis", null);
System.out.println("Log:========this is insert opertation=====");
DBInstance(DBparam).delete("deleteCurr", null);
System.out.println("Log:========this is delete opertation=====");
DBInstance(DBparam).commitTransaction();
} catch (Exception e) {
e.printStackTrace();
}finally{
try {
DBInstance(DBparam).endTransaction();
} catch (SQLException e) {
e.printStackTrace();
}
}
}定時程序:@Override
public void contextInitialized(ServletContextEvent arg0) {
// TODO Auto-generated method stub
timer = new Timer();
timeSimple = new TimeSimple();
SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String now = sf.format(new Date());
String result = now.substring(0,11)+time;
System.out.println(now+"~~~~~~~~~~~~~~~~~~~"+result);
System.out.println(now.substring(13));
try {
long target = sf.parse(result).getTime()-new Date().getTime();
System.out.print("the method will be start after "+target);
timer.schedule(timeSimple, target<0?target+24*60*60*1000:target, 24*60*60*1000);
} catch (ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}日誌信息:2012-04-18 10:00:00,102 DEBUG PreparedStatement:23 - {pstm-103295} PreparedStatement: insert into HisSummary select sycom, TableNumber, TableAreaType, GameDay, OccurenceTime, WinLossAmount, Status, RegDate, CurrFlag, Turnover from CurrTabSumry WHERE GameDay<>(select max(GameDay) GameDay from CurrTabSumry (nolock) )
2012-04-18 10:00:00,118 DEBUG PreparedStatement:23 - {pstm-103295} Parameters: []
2012-04-18 10:00:00,118 DEBUG PreparedStatement:23 - {pstm-103295} Types: []
2012-04-18 10:00:05~~~~~~~~~~~~~~~~~~~2012-04-18 10:00:00
:00:05
the method will be start after -59622012-04-18 10:00:06,368 INFO CheckSessionOutFilter:53 - /js/LoadSummary.jsp
2012-04-18 10:00:06,368 INFO CheckSessionOutFilter:54 - loginName=05897;gameday=2012-04-18;
sqlMapClient initing.....
2012-04-18 10:00:07,196 DEBUG Connection:23 - {conn-100000} Connection
2012-04-18 10:00:07,259 DEBUG PreparedStatement:23 - {pstm-100001} PreparedStatement: select ID,sycom,companyname ,description,propertyVal from property order by sycom
2012-04-18 10:00:07,259 DEBUG PreparedStatement:23 - {pstm-100001} Parameters: []
2012-04-18 10:00:07,274 DEBUG PreparedStatement:23 - {pstm-100001} Types: []
2012-04-18 10:00:07,290 DEBUG ResultSet:23 - {rset-100002} ResultSet
代码: /**
* 2012-03-15
* @param DBparam
* @throws Exception
*/
public void currToHis(String DBparam,int s) {
try {
DBInstance(DBparam).startTransaction(Connection.TRANSACTION_SERIALIZABLE);
DBInstance(DBparam).insert("currtoHis", null);
System.out.println("Log:========this is insert opertation=====");
DBInstance(DBparam).delete("deleteCurr", null);
System.out.println("Log:========this is delete opertation=====");
DBInstance(DBparam).commitTransaction();
} catch (Exception e) {
e.printStackTrace();
}finally{
try {
DBInstance(DBparam).endTransaction();
} catch (SQLException e) {
e.printStackTrace();
}
}
}定時程序:@Override
public void contextInitialized(ServletContextEvent arg0) {
// TODO Auto-generated method stub
timer = new Timer();
timeSimple = new TimeSimple();
SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String now = sf.format(new Date());
String result = now.substring(0,11)+time;
System.out.println(now+"~~~~~~~~~~~~~~~~~~~"+result);
System.out.println(now.substring(13));
try {
long target = sf.parse(result).getTime()-new Date().getTime();
System.out.print("the method will be start after "+target);
timer.schedule(timeSimple, target<0?target+24*60*60*1000:target, 24*60*60*1000);
} catch (ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}日誌信息:2012-04-18 10:00:00,102 DEBUG PreparedStatement:23 - {pstm-103295} PreparedStatement: insert into HisSummary select sycom, TableNumber, TableAreaType, GameDay, OccurenceTime, WinLossAmount, Status, RegDate, CurrFlag, Turnover from CurrTabSumry WHERE GameDay<>(select max(GameDay) GameDay from CurrTabSumry (nolock) )
2012-04-18 10:00:00,118 DEBUG PreparedStatement:23 - {pstm-103295} Parameters: []
2012-04-18 10:00:00,118 DEBUG PreparedStatement:23 - {pstm-103295} Types: []
2012-04-18 10:00:05~~~~~~~~~~~~~~~~~~~2012-04-18 10:00:00
:00:05
the method will be start after -59622012-04-18 10:00:06,368 INFO CheckSessionOutFilter:53 - /js/LoadSummary.jsp
2012-04-18 10:00:06,368 INFO CheckSessionOutFilter:54 - loginName=05897;gameday=2012-04-18;
sqlMapClient initing.....
2012-04-18 10:00:07,196 DEBUG Connection:23 - {conn-100000} Connection
2012-04-18 10:00:07,259 DEBUG PreparedStatement:23 - {pstm-100001} PreparedStatement: select ID,sycom,companyname ,description,propertyVal from property order by sycom
2012-04-18 10:00:07,259 DEBUG PreparedStatement:23 - {pstm-100001} Parameters: []
2012-04-18 10:00:07,274 DEBUG PreparedStatement:23 - {pstm-100001} Types: []
2012-04-18 10:00:07,290 DEBUG ResultSet:23 - {rset-100002} ResultSet
---------
推荐使用Executors.newScheduledThreadPool(...).shedule...,这种方式run抛出异常不会导致定时任务终止
上面的那个程序出现异常,为什么捕获不到呢?还有这个定时任务他还会执行,就是每天10:00做这个任务,今天失败了,明天有可能成功,后天又不定了。其实我想要的结果是想把异常信息得到,查看具体的原因,比如sql 错误等。
后面的system.out.print 没有打印,怀疑出现了异常,但是异常信息也没有打印谢谢指教啊
方法中可能拋異常的地方都是try了的,只要有異常,肯定會被catch,你捕捉的是Exception,涵蓋所有異常
控制臺沒打印出異常信息嗎?可能需要等足夠時間