日期:2014-05-20  浏览次数:20793 次

在线等!Ibatis 与 Tomcat问题!!!
我的Mysql数据库有10个数据库,每个数据库有 100张同样的表。

Service 层 Sql语句

public synchronized List<PosOrder> executeFindPayMoneyList(String where)
throws Exception {
List<PosOrder> orderList = new ArrayList<PosOrder>();
Map<String, String> paramMap = new HashMap<String, String>();
paramMap.put("status", "1");
paramMap.put("delivery", "0");
paramMap.put("buyType", "1");
paramMap.put("where", where);
//循环10个数据库
for(int i = 0;i<10;i++){
//循环100张表
for(int j = 0;j<100;j++){
int m = j /10;
int n = j % 10;
paramMap.put("dataBaseName", "pay" + i);
paramMap.put("tableName", "t_pos_order_" + m+n);
orderList.addAll(client2.queryForList(
"findAllOrderByStatusAndDelivery", paramMap));
}
}


return orderList;
}

我的Xml配置文件

<select id="findAllOrderByStatusAndDelivery" resultMap="PosOrderResult" resultClass="PosOrder" parameterClass="java.util.Map"> select * from $dataBaseName$.$tableName$ where 1=1 and F_disable = 0 and F_status = $status$ and F_delivery = $delivery$ and F_buy_type = $buyType$ $where$ </select>

我执行 executeFindPayMoneyList(null)方法的时候, 访问数据库的Sql语句是

select * from pay0.t_pos_order_00 where 1=1 and F_disable = 0 and F_status = 1 and F_delivery = 0 and F_buy_type = 1  

select * from pay0.t_pos_order_01 where 1=1 and F_disable = 0 and F_status = 1 and F_delivery = 0 and F_buy_type = 1  

select * from pay0.t_pos_order_02 where 1=1 and F_disable = 0 and F_status = 1 and F_delivery = 0 and F_buy_type = 1  

...

然后 下一个数据库 ,注意 pay0 改成 pay1了

select * from pay1.t_pos_order_00 where 1=1 and F_disable = 0 and F_status = 1 and F_delivery = 0 and F_buy_type = 1  

select * from pay1.t_pos_order_01 where 1=1 and F_disable = 0 and F_status = 1 and F_delivery = 0 and F_buy_type = 1  

select * from pay1.t_pos_order_02 where 1=1 and F_disable = 0 and F_status = 1 and F_delivery = 0 and F_buy_type = 1  

最后一直到 

select * from pay9.t_pos_order_99 where 1=1 and F_disable = 0 and F_status = 1 and F_delivery = 0 and F_buy_type = 1  



每次一个请求都会启动一个新的线程,来这样子访问数据库,请求多了,我这里 Tomcat就挂掉了,查看 Tomcat Logs日志记录的话,说是内存溢出了。

这是记录:
Sep 29, 2011 12:58:09 PM org.apache.catalina.loader.WebappClassLoader clearReferencesJdbc
SEVERE: The web application [/JXCManager] registered the JDBC driver [com.mysql.jdbc.Driver] but failed to unregister it when the web application was stopped. To prevent a memory leak, the JDBC Driver has been forcibly unregistered.
Sep 29, 2011 12:58:09 PM org.apache.catalina.loader.WebappClassLoader clearReferencesThreads
SEVERE: The web application [/JXCManager] appears to have started a thread named [MySQL Statement Cancellation Timer] but has failed to stop it. This is very likely to create a memory leak.
Sep 29, 2011 12:58:09 PM org.apache.catalina.loader.WebappClassLoader clearThreadLocalMap
SEVERE: The web application [/JXCManager] created a ThreadLocal with key of type [com.opensymphony.xwork2.inject.ContainerImpl$10] (value [com.opensymphony.xwork2.inject.ContainerImpl$10@1bfefb]) and a value of type [java.lang.Object[]] (value [[Ljava.lang.Object;@13ada]) but failed to remove it when the web application was stopped. This is very likely to create a memory leak.
Sep 29, 2011 12:58:09 PM org.apache.catalina.loader.WebappClassLoader clearThreadLocalMap
SEVERE: The web application [/JXCManager] created a ThreadLocal with key of type [com.opensymphony.xwork2.inject.ContainerImpl$10] (value [com.opensymphony.xwork2.inject.ContainerImpl$10@bed4c8]) and a value of type [java.lang.Object[]] (value [[Ljava.lang.Object;@8398e7]) but failed to remove it when the web application was stopped. This is very likely to create a memory leak.