我的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.
有朋友有解决方案吗?

解决方案 »

  1.   

    请问你是要测试你的tomcat的性能吗?
      

  2.   

    存储过程,可以考虑,我这里出现的问题是 Tomcat挂掉了,有在 程序中解决的方法吗、?
      

  3.   

    这么大的数据量而且还是并发tomcat是扛不住的,大型的数据处理一般都是分布式系统,你应该考虑分布式!
      

  4.   

    这么大的数据量而且还是并发tomcat是扛不住的,大型的数据处理一般都是分布式系统,你应该考虑分布式!
      

  5.   

    这么大的数据量而且还是并发tomcat是扛不住的,大型的数据处理一般都是分布式系统,你应该考虑分布式!
      

  6.   

    我的Mysql数据库有10个数据库,每个数据库有 100张同样的表。
    你这是什么需求?为什么要相同的表?能给解释一下么?
      

  7.   


    我的数据库是 分库分表的,插入一条数据,根据 算法运算,然后插入到哪个数据库哪张表
    如:前台 注册一个用户,在后台处理的时候,对这个用户资料进行算法运算,得出结果是 pay3.t_order_33这张表以后,然后进行插入到这 pay3.t_order_33 这个表中。相同的表结构可以拆分,可以进行分布式,很方便。
      

  8.   

    思路不是给你了么?你是要代码吧
    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);
    }
    }
      

  9.   


    朋友,你的思路给了我思路,一个分页的思路,首先,我会count一下每个表的数据数量,当数量大于或等于 start 数之后 ,保存当前数据库和当前表,然后 从保存的数据库和当前表开始查,limit 数量是否大于 pageSize 如果不大于 则继续查,大于则返回。