读书人

!Ibatis 与 Tomcat有关问题!

发布时间: 2012-03-09 21:42:53 作者: rapoo

在线等!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.


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;@1ab6c1c]) 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 [java.lang.ThreadLocal] (value [java.lang.ThreadLocal@146ac5a]) and a value of type [com.ibatis.sqlmap.engine.mapping.result.ResultObjectFactoryUtil.FactorySettings] (value [com.ibatis.sqlmap.engine.mapping.result.ResultObjectFactoryUtil$FactorySettings@12b9f79]) 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 [java.lang.ThreadLocal] (value [java.lang.ThreadLocal@f2db2d]) and a value of type [com.ibatis.sqlmap.engine.impl.SqlMapSessionImpl] (value [com.ibatis.sqlmap.engine.impl.SqlMapSessionImpl@13a356]) 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@1bfefb]) and a value of type [java.lang.Object[]] (value [[Ljava.lang.Object;@1489ea3]) 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;@a6faa9]) 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@928739]) and a value of type [java.lang.Object[]] (value [[Ljava.lang.Object;@1ebe8ec]) 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@1bfefb]) and a value of type [java.lang.Object[]] (value [[Ljava.lang.Object;@108f060]) 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 [java.lang.ThreadLocal] (value [java.lang.ThreadLocal@146ac5a]) and a value of type [com.ibatis.sqlmap.engine.mapping.result.ResultObjectFactoryUtil.FactorySettings] (value [com.ibatis.sqlmap.engine.mapping.result.ResultObjectFactoryUtil$FactorySettings@1dd5a3d]) 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 [java.lang.ThreadLocal] (value [java.lang.ThreadLocal@f2db2d]) and a value of type [com.ibatis.sqlmap.engine.impl.SqlMapSessionImpl] (value [com.ibatis.sqlmap.engine.impl.SqlMapSessionImpl@14f7a86]) 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@1bfefb]) and a value of type [java.lang.Object[]] (value [[Ljava.lang.Object;@f4fb44]) 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@1bfefb]) and a value of type [java.lang.Object[]] (value [[Ljava.lang.Object;@19c4364]) but failed to remove it when the web application was stopped. This is very likely to create a memory leak.
有朋友有解决方案吗?

[解决办法]
这么大的数据量而且还是并发tomcat是扛不住的,大型的数据处理一般都是分布式系统,你应该考虑分布式!
[解决办法]
弄个视图!
[解决办法]
思路不是给你了么?你是要代码吧

Java code
    public static void main(String[] args) throws Exception {        int[][] rowCount = new int[10][100];        for (int i = 0; i < rowCount.length; i++) {            for (int j = 0, length = rowCount[i].length; j < length; j++) {                rowCount[i][j] = i + j + 10;// "SELECT COUNT(*) FROM dbName"+i+".tableName"+j+" WHERE condition"                if (i == 0 && j < 20) {                    System.out.print(rowCount[i][j] + " ");                }            }        }        System.out.println();        int currentPage = 50;// 前台值        int pageSize = 20;// 前台值        int start = currentPage * pageSize;        int end = 0;        boolean isOverTwoTable = false;        Integer dbIndex = null;        Integer tableIndex = null;        Integer overDbIndex = null;        Integer overTableIndex = null;        outter: for (int i = 0; i < rowCount.length; i++) {            for (int j = 0, length = rowCount[i].length; j < length; j++) {                if (rowCount[i][j] < start) {                    start = start - rowCount[i][j];                } else {                    if (rowCount[i][j] > start + pageSize) {// 没有跨表分页                        dbIndex = new Integer(i);                        tableIndex = new Integer(j);                    } else {// 有跨表分页,简化处理假设每个表数据量>10                        isOverTwoTable = true;                        dbIndex = new Integer(i);                        tableIndex = new Integer(j);                        end = start + pageSize - rowCount[i][j];                        if ((j + 1) > length) {                            overDbIndex = new Integer(i + 1);                            overTableIndex = new Integer(0);                        } else {                            overDbIndex = new Integer(i);                            overTableIndex = new Integer(j + 1);                        }                    }                    break outter;                }            }        }        if (isOverTwoTable) {            System.out.println("SELECT * FROM dbName" + dbIndex + ".tableName"                    + tableIndex + " WHERE condition limit " + start + ","                    + pageSize);            System.out.println("SELECT * FROM dbName" + overDbIndex                    + ".tableName" + overTableIndex + " WHERE condition limit "                    + 0 + "," + end);        } else {            System.out.println("SELECT * FROM dbName" + dbIndex + ".tableName"                    + tableIndex + " WHERE condition limit " + start + ","                    + pageSize);        }    } 

读书人网 >J2EE开发

热点推荐