您的位置:首页 > 移动开发

APPARENT DEADLOCK!!![proxool+Spring集成]

2015-10-21 10:56 423 查看
我终于也遇到c3p0的bug了!!!!!

com.mchange.v2.async.ThreadPoolAsynchronousRunner$DeadlockDetector@67b2ccc4 – APPARENT DEADLOCK!!! Creating emergency threads for unassigned pending tasks!

没办法,换proxool试试吧,附上proxool配置方案:

1).proxool.xml文件

<?xml version="1.0" encoding="UTF-8"?>
<something-else-entirely>
<proxool>
<alias>dbpool</alias>
<driver-url>jdbc:mysql://192.168.2.10:3306/kingshine?useUnicode=true&characterEncoding=UTF-8</driver-url>
<driver-class>com.mysql.jdbc.Driver</driver-class>
<driver-properties>
<property name="user" value="root"/>
<property name="password" value="kingshine"/>
</driver-properties>
<!-- proxool自动侦查各个连接状态的时间间隔(毫秒),侦查到空闲的连接就马上 回收,超时的销毁 -->
<house-keeping-sleep-time>900000</house-keeping-sleep-time>
<!-- 最大连接数 -->
<maximum-connection-count>10</maximum-connection-count>
<!-- 最小连接数 -->
<minimum-connection-count>3</minimum-connection-count>
<!--连接池中可用的连接数量.如果当前的连接池中的连接少于这个数值.新的连接将被建立 -->
<prototype-count>3</prototype-count>
<!-- 可一次建立的最大连接数。那就是新增的连接请求,但还没有可供使用的连接,默认为10 -->
<simultaneous-build-throttle>4</simultaneous-build-throttle>
<!-- 日志统计跟踪类型。参数“ERROR”或 “INFO” -->
<statistics-log-level>INFO</statistics-log-level>
<house-keeping-test-sql>select CURRENT_DATE</house-keeping-test-sql>
</proxool>
</something-else-entirely>


2).applicationContext.xml文件(Spring配置文件)

<bean
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="locations">
<list>
<value>classpath:jdbc.properties</value>
</list>
</property>
</bean>

<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName">
<value>org.logicalcobwebs.proxool.ProxoolDriver</value>
</property>
<property name="url">
<value>proxool.dbpool</value>
</property>
</bean>

<!-- 配置Hibernate -->
<bean id="sessionFactory" lazy-init ="true"
class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
<property name="dataSource">
<ref bean="dataSource" />
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">${hibernate.dialect}</prop>
<prop key="hibernate.show_sql">${hibernate.show_sql}</prop>
<prop key="hibernate.format_sql">${hibernate.format_sql}</prop>
<prop key="hibernate.generate_statistics">true</prop>
<prop key="hibernate.connection.release_mode">auto</prop>
<prop key="hibernate.autoReconnect">true</prop>
<prop key="hibernate.jdbc.fetch_size">50</prop>
</props>
</property>
<!--        <property name="mappingResources"> -->
<!--            <list> -->
<!--                <value>classpath*:com/kingshine/*/bean/*.hbm.xml</value> -->
<!--            </list> -->
<!--        </property> -->
<!-- hibernate注解扫描 -->
<property name="packagesToScan" value="com.kingshine.*.bean" />
</bean>


3).自定义Listener(为了在Spring配置文件加载之前加载proxool配置文件)

package com.kingshine.common.listener;

import java.io.File;
import java.util.Properties;

import javax.servlet.ServletContextEvent;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.logicalcobwebs.proxool.ProxoolException;
import org.logicalcobwebs.proxool.ProxoolFacade;
import org.logicalcobwebs.proxool.configuration.JAXPConfigurator;
import org.logicalcobwebs.proxool.configuration.PropertyConfigurator;
/**
* proxool初始化
* @author
* @date
*/
public class ProxoolListenerConfigurator implements
javax.servlet.ServletContextListener {

private static final Log LOG = LogFactory
.getLog(ProxoolListenerConfigurator.class);

private static final String XML_FILE_PROPERTY = "proxoolConfigLocation";

private boolean autoShutdown = true;

public void contextInitialized(ServletContextEvent servletConfig) {

String appDir = servletConfig.getServletContext().getRealPath("/");

Properties properties = new Properties();
String value = servletConfig.getServletContext().getInitParameter(
XML_FILE_PROPERTY);
LOG.info("proxoolConfigLocation:"+value);

try {
File file = new File(value);
if (file.isAbsolute()) {
JAXPConfigurator.configure(value, false);
} else {
LOG.debug(appDir + File.separator + value);
JAXPConfigurator.configure(appDir + File.separator + value,
false);
}
} catch (ProxoolException e) {
LOG.error("Problem configuring " + value, e);
}
if (properties.size() > 0) {
try {
PropertyConfigurator.configure(properties);
} catch (ProxoolException e) {
LOG.error("Problem configuring using init properties", e);
}
}
}

public void contextDestroyed(ServletContextEvent s) {
if (autoShutdown) {
ProxoolFacade.shutdown(0);
}
}
}


4).web.xml

<context-param>
<param-name>proxoolConfigLocation</param-name>
<param-value>WEB-INF/classes/proxool.xml</param-value>
</context-param>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:applicationContext*.xml</param-value>
</context-param>
<context-param>
<param-name>webAppRootKey</param-name>
<param-value>system.root.kingshine</param-value>
</context-param>
<context-param>
<param-name>log4jConfigLocation</param-name>
<param-value>classpath:log4j.properties</param-value>
</context-param>

<listener>
<listener-class>com.kingshine.common.listener.ProxoolListenerConfigurator</listener-class>
</listener>
<listener>
<listener-class>org.springframework.web.util.Log4jConfigListener</listener-class>
</listener>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<listener>
<listener-class>org.springframework.web.util.IntrospectorCleanupListener</listener-class>
</listener>
<listener>
<listener-class>com.kingshine.common.listener.SystemSessionListener</listener-class>
</listener>
<filter>
<filter-name>openSessionInView</filter-name>
<filter-class>org.springframework.orm.hibernate4.support.OpenSessionInViewFilter</filter-class>
<init-param>
<param-name>sessionFactoryBeanName</param-name>
<param-value>sessionFactory</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>openSessionInView</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<filter>
<filter-name>struts2</filter-name>
<filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>*.action</url-pattern>
</filter-mapping>

<!-- 配置proxool资源监控程序 -->
<servlet>
<servlet-name>adminP</servlet-name>
<servlet-class>
org.logicalcobwebs.proxool.admin.servlet.AdminServlet
</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>adminP</servlet-name>
<url-pattern>/adminp</url-pattern>
</servlet-mapping>


OK,完事可以看一下proxool的控制台:

http://localhost:8080/项目名称/adminp
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: