。。
public void run() {
while (true) {
try{
readList() ;
}catch(Exception e){
log().error("",e);
}
}
}
private List<CMPP2AbstractMessage> readList() {
Session ssn = null;
Connection con = null;
PreparedStatement pre = null;
ResultSet rs = null;
List<NewSmsBeenSentNumber> smsSent = new ArrayList<NewSmsBeenSentNumber>();
try {
//log().info("read data to send--->get the datebase session----->begin"); ssn = HibernateSessionFactory.currentSession();
//log().info("read data to send--->get the datebase session----->over!"); con = ssn.connection();
log().info("read data to send--->get the datebase conection--->over!");
String str = "select DN_NEEDREPLY, DC_SERVID, phoneId, DC_DST_ID, s.dn_id as      dnSmsId, contentId, DC_EXTMARKID, dn_feeusertype,";
str += "             DC_FEETERMID, nc.DN_FORMAT, dc_feeType, dc_feecode, dc_srcid, nc.DC_CONTENT, DN_PK_NUMBER, DN_PK_TOTAL";
str += "      from";

                           str += "      on s.dn_id = nc.dn_sms_id"; pre = con.prepareStatement(str);
pre.setQueryTimeout(60 * 2);//SQL语句执行超时时间为2分钟
log().info("query data-->begin");
rs = pre.executeQuery();
log().info("query data->return back"); 
while (rs.next())
{
NewSmsBeenSentNumber bean = new NewSmsBeenSentNumber();
int dnNeedreply = rs.getInt("DN_NEEDREPLY");
bean.setDnNeedRly(dnNeedreply);
String dcServId = rs.getString("DC_SERVID");
bean.setDcServid(dcServId);
.......
smsSent.add(bean);
}
} catch (Exception e) {
log().error("", e);
} finally {
try {
rs.close();
} catch (Exception e) {
}
try {
pre.close();
} catch (Exception e) {
}
HibernateSessionFactory.closeSession();
}
// 
}问题是这样的  以上标红的两行 注释的log ,在注释的情况下程序运行效率非常慢,去掉注释效率很快,非常不解,求高人解释原因

解决方案 »

  1.   

    应该不会存在这种问题!那个 LOG 就输出了个字符串。
      

  2.   

    以上是发短信取数据的部分代码,有速度要求,之前没有问题,后来服务器挂掉了,再重新部署就出现发送速度慢的问题,我去掉log目的也是为了去测试哪里有问题,但是我发现又恢复到以前的速度了,然后注释掉log速度又慢了。问题是解决了,但是解释不通是什么原因
      

  3.   

    你的log()是个函数调用。该函数调用有什么特殊性么?比如得到日志记录对象的代价太高,或者做了什么synchronized啥的?
      

  4.   


    private Logger log() {
    return ThreadLogger.getInstance();
    }
      

  5.   

    这把问题给深化了,变成是 ThreadLogger.getInstance() 里面的实现有多复杂,是否有同步之类的问题了。也许你应该在函数开始的时候直接:
      Logger log = log();
    后面就直接用log变量,避免重复调用了。