很简单的一个实例..jsp->ejb2->dbsql在DB跑很快,不用1s,但实例运行缺要15S!java代码:public class LineDAO {
Connection con=null;
private Logger logger = LogManager.getLogger(LineDAO.class);
public LineDAO(){
Context ctx;
try {
long ta=System.currentTimeMillis();
ctx = new javax.naming.InitialContext();
DataSource ds = (DataSource)ctx.lookup("java:OracleDS");
con=ds.getConnection();
logger.debug("Get Connection time:"+(System.currentTimeMillis()-ta)+"ms");
} catch (NamingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
Collection getLineNO(String custno){
ArrayList result=new ArrayList();
String sql="select line_no From lis_line_subscription where cust_cd='"+custno+"'";
try {
long tb=System.currentTimeMillis();
PreparedStatement smt=con.prepareStatement(sql);
ResultSet rs=smt.executeQuery();
while(rs.next()){
result.add(rs.getString(1));
}
logger.debug("Query time:"+(System.currentTimeMillis()-tb)+"ms");
rs.close();
smt.close();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}finally {
try {
if (con != null) {
con.close();
}
} catch (SQLException e1) {
e1.printStackTrace();
}
}
return result;
}
}还有问下如果要使用jboss本身的log4j是否xml加入以下就可以了<category name="com.nwt.LineDAO">
<priority value="DEBUG" />
<appender-ref ref="CONSOLE" />
</category>
<root>但配置了无效,没有输出么..
Connection con=null;
private Logger logger = LogManager.getLogger(LineDAO.class);
public LineDAO(){
Context ctx;
try {
long ta=System.currentTimeMillis();
ctx = new javax.naming.InitialContext();
DataSource ds = (DataSource)ctx.lookup("java:OracleDS");
con=ds.getConnection();
logger.debug("Get Connection time:"+(System.currentTimeMillis()-ta)+"ms");
} catch (NamingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
Collection getLineNO(String custno){
ArrayList result=new ArrayList();
String sql="select line_no From lis_line_subscription where cust_cd='"+custno+"'";
try {
long tb=System.currentTimeMillis();
PreparedStatement smt=con.prepareStatement(sql);
ResultSet rs=smt.executeQuery();
while(rs.next()){
result.add(rs.getString(1));
}
logger.debug("Query time:"+(System.currentTimeMillis()-tb)+"ms");
rs.close();
smt.close();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}finally {
try {
if (con != null) {
con.close();
}
} catch (SQLException e1) {
e1.printStackTrace();
}
}
return result;
}
}还有问下如果要使用jboss本身的log4j是否xml加入以下就可以了<category name="com.nwt.LineDAO">
<priority value="DEBUG" />
<appender-ref ref="CONSOLE" />
</category>
<root>但配置了无效,没有输出么..
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货