Erro no Hibernate com C3P0

galera, as vezes esta ocrrendo este problema no meu hibernate, ele nao afeta seriamente o sistema, na verdade não sei nem o q ele quer dizer, se alguem puder me ajudar

09:58:33,034 WARN  [com.mchange.v2.resourcepool.BasicResourcePool] (com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread-#0) Failed to destroy resource: com.mchange.v2.c3p0.impl.NewPooledConnection@21ce5297: java.util.ConcurrentModificationException
	at java.util.HashMap$HashIterator.nextEntry(Unknown Source) [rt.jar:1.7.0]
	at java.util.HashMap$KeyIterator.next(Unknown Source) [rt.jar:1.7.0]
	at com.mysql.jdbc.ConnectionImpl.closeAllOpenStatements(ConnectionImpl.java:1575) [mysql-connector-java-5.1.18-bin.jar:]
	at com.mysql.jdbc.ConnectionImpl.realClose(ConnectionImpl.java:4364) [mysql-connector-java-5.1.18-bin.jar:]
	at com.mysql.jdbc.ConnectionImpl.close(ConnectionImpl.java:1556) [mysql-connector-java-5.1.18-bin.jar:]
	at com.mchange.v2.c3p0.impl.NewPooledConnection.close(NewPooledConnection.java:474) [c3p0-0.9.1.jar:0.9.1]
	at com.mchange.v2.c3p0.impl.NewPooledConnection.close(NewPooledConnection.java:191) [c3p0-0.9.1.jar:0.9.1]
	at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool$1PooledConnectionResourcePoolManager.destroyResource(C3P0PooledConnectionPool.java:470) [c3p0-0.9.1.jar:0.9.1]
	at com.mchange.v2.resourcepool.BasicResourcePool$1DestroyResourceTask.run(BasicResourcePool.java:964) [c3p0-0.9.1.jar:0.9.1]
	at com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread.run(ThreadPoolAsynchronousRunner.java:547) [c3p0-0.9.1.jar:0.9.1]

10:02:52,902 WARN  [com.mchange.v2.async.ThreadPoolAsynchronousRunner] (Timer-10) com.mchange.v2.async.ThreadPoolAsynchronousRunner$DeadlockDetector@38f05529 -- APPARENT DEADLOCK!!! Creating emergency threads for unassigned pending tasks!
10:02:53,801 WARN  [com.mchange.v2.async.ThreadPoolAsynchronousRunner] (Timer-10) com.mchange.v2.async.ThreadPoolAsynchronousRunner$DeadlockDetector@38f05529 -- APPARENT DEADLOCK!!! Complete Status: 
	Managed Threads: 3
	Active Threads: 3
	Active Tasks: 
		com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask@2844b01d (com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread-#0)
		com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask@35865492 (com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread-#1)
		com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask@61a58b2 (com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread-#2)
	Pending Tasks: 
		com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask@2bb5113f
		com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask@7c7f5583
		com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask@bc74b50
		com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask@4921773a
		com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask@341aa658
		com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask@419ef621
Pool thread stack traces:
	Thread[com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread-#0,5,main]
		java.lang.Object.wait(Native Method)
		java.lang.Object.wait(Object.java:503)
		java.net.InetAddress.checkLookupTable(Unknown Source)
		java.net.InetAddress.getAddressesFromNameService(Unknown Source)
		java.net.InetAddress.getAllByName0(Unknown Source)
		java.net.InetAddress.getAllByName(Unknown Source)
		java.net.InetAddress.getAllByName(Unknown Source)
		com.mysql.jdbc.StandardSocketFactory.connect(StandardSocketFactory.java:247)
		com.mysql.jdbc.MysqlIO.<init>(MysqlIO.java:294)
		com.mysql.jdbc.ConnectionImpl.coreConnect(ConnectionImpl.java:2332)
		com.mysql.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:2369)
		com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2153)
		com.mysql.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:792)
		com.mysql.jdbc.JDBC4Connection.<init>(JDBC4Connection.java:47)
		sun.reflect.GeneratedConstructorAccessor166.newInstance(Unknown Source)
		sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
		java.lang.reflect.Constructor.newInstance(Unknown Source)
		com.mysql.jdbc.Util.handleNewInstance(Util.java:411)
		com.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:381)
		com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:305)
		com.mchange.v2.c3p0.DriverManagerDataSource.getConnection(DriverManagerDataSource.java:135)
		com.mchange.v2.c3p0.WrapperConnectionPoolDataSource.getPooledConnection(WrapperConnectionPoolDataSource.java:182)
		com.mchange.v2.c3p0.WrapperConnectionPoolDataSource.getPooledConnection(WrapperConnectionPoolDataSource.java:171)
		com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool$1PooledConnectionResourcePoolManager.acquireResource(C3P0PooledConnectionPool.java:137)
		com.mchange.v2.resourcepool.BasicResourcePool.doAcquire(BasicResourcePool.java:1014)
		com.mchange.v2.resourcepool.BasicResourcePool.access$800(BasicResourcePool.java:32)
		com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask.run(BasicResourcePool.java:1810)
		com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread.run(ThreadPoolAsynchronousRunner.java:547)
	Thread[com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread-#1,5,main]
		java.lang.Object.wait(Native Method)
		java.lang.Object.wait(Object.java:503)
		java.net.InetAddress.checkLookupTable(Unknown Source)
		java.net.InetAddress.getAddressesFromNameService(Unknown Source)
		java.net.InetAddress.getAllByName0(Unknown Source)
		java.net.InetAddress.getAllByName(Unknown Source)
		java.net.InetAddress.getAllByName(Unknown Source)
		com.mysql.jdbc.StandardSocketFactory.connect(StandardSocketFactory.java:247)
		com.mysql.jdbc.MysqlIO.<init>(MysqlIO.java:294)
		com.mysql.jdbc.ConnectionImpl.coreConnect(ConnectionImpl.java:2332)
		com.mysql.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:2369)
		com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2153)
		com.mysql.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:792)
		com.mysql.jdbc.JDBC4Connection.<init>(JDBC4Connection.java:47)
		sun.reflect.GeneratedConstructorAccessor166.newInstance(Unknown Source)
		sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
		java.lang.reflect.Constructor.newInstance(Unknown Source)
		com.mysql.jdbc.Util.handleNewInstance(Util.java:411)
		com.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:381)
		com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:305)
		com.mchange.v2.c3p0.DriverManagerDataSource.getConnection(DriverManagerDataSource.java:135)
		com.mchange.v2.c3p0.WrapperConnectionPoolDataSource.getPooledConnection(WrapperConnectionPoolDataSource.java:182)
		com.mchange.v2.c3p0.WrapperConnectionPoolDataSource.getPooledConnection(WrapperConnectionPoolDataSource.java:171)
		com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool$1PooledConnectionResourcePoolManager.acquireResource(C3P0PooledConnectionPool.java:137)
		com.mchange.v2.resourcepool.BasicResourcePool.doAcquire(BasicResourcePool.java:1014)
		com.mchange.v2.resourcepool.BasicResourcePool.access$800(BasicResourcePool.java:32)
		com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask.run(BasicResourcePool.java:1810)
		com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread.run(ThreadPoolAsynchronousRunner.java:547)
	Thread[com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread-#2,5,main]
		java.net.Inet4AddressImpl.lookupAllHostAddr(Native Method)
		java.net.InetAddress$1.lookupAllHostAddr(Unknown Source)
		java.net.InetAddress.getAddressesFromNameService(Unknown Source)
		java.net.InetAddress.getAllByName0(Unknown Source)
		java.net.InetAddress.getAllByName(Unknown Source)
		java.net.InetAddress.getAllByName(Unknown Source)
		com.mysql.jdbc.StandardSocketFactory.connect(StandardSocketFactory.java:247)
		com.mysql.jdbc.MysqlIO.<init>(MysqlIO.java:294)
		com.mysql.jdbc.ConnectionImpl.coreConnect(ConnectionImpl.java:2332)
		com.mysql.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:2369)
		com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2153)
		com.mysql.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:792)
		com.mysql.jdbc.JDBC4Connection.<init>(JDBC4Connection.java:47)
		sun.reflect.GeneratedConstructorAccessor166.newInstance(Unknown Source)
		sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
		java.lang.reflect.Constructor.newInstance(Unknown Source)
		com.mysql.jdbc.Util.handleNewInstance(Util.java:411)
		com.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:381)
		com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:305)
		com.mchange.v2.c3p0.DriverManagerDataSource.getConnection(DriverManagerDataSource.java:135)
		com.mchange.v2.c3p0.WrapperConnectionPoolDataSource.getPooledConnection(WrapperConnectionPoolDataSource.java:182)
		com.mchange.v2.c3p0.WrapperConnectionPoolDataSource.getPooledConnection(WrapperConnectionPoolDataSource.java:171)
		com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool$1PooledConnectionResourcePoolManager.acquireResource(C3P0PooledConnectionPool.java:137)
		com.mchange.v2.resourcepool.BasicResourcePool.doAcquire(BasicResourcePool.java:1014)
		com.mchange.v2.resourcepool.BasicResourcePool.access$800(BasicResourcePool.java:32)
		com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask.run(BasicResourcePool.java:1810)
		com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread.run(ThreadPoolAsynchronousRunner.java:547)

vc esta fechando suas sessions apos utiliza-las?

Acredito que sim, segue abaixo meu xml do hibernate e as classes de conexao que uso:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC
		"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
		"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
	<session-factory>
		<property name="hibernate.connection.driver_class">org.gjt.mm.mysql.Driver</property>
		<property name="hibernate.connection.password">****</property>
		<property name="hibernate.connection.url">*****</property>
		<property name="hibernate.connection.username">****</property>
		<property name="hibernate.dialect">org.hibernate.dialect.MySQL5InnoDBDialect</property>
		<property name="hibernate.hbm2ddl.auto">update</property>
		<property name="show_sql">true</property>
		<property name="format_sql">true</property>
		
		<!-- configuration pool via c3p0--> 
		<property name="c3p0.acquire_increment">10</property> 
		<property name="c3p0.idle_test_period">100</property> <!-- seconds --> 
		<property name="c3p0.max_size">100</property> 
		<property name="c3p0.max_statements">10</property> 
		<property name="c3p0.min_size">10</property> 
		<property name="c3p0.timeout">100</property> <!-- seconds --> 
		<!-- DEPRECATED very expensive property name="c3p0.validate>--> 

		<!-- Entitys -->
		<mapping class="br.com.comparaescola.model.entity.****" />
		
	</session-factory>
</hibernate-configuration>
@Component
public class CriadorDeSession implements ComponentFactory<Session> {
    
    private final SessionFactory factory;
    private Session session;

    public CriadorDeSession(SessionFactory factory) {
        this.factory = factory;
    }    
    
    @PostConstruct
    public void abre(){
        this.session = factory.openSession();
      
    }
    
    public Session getInstance() {
        return session;
    }
    
    @PreDestroy
    public void fecha(){
        session.close();
      
    }
@Component
@ApplicationScoped
public class CriadorDeSessionFactory implements ComponentFactory<SessionFactory> {
    
    private SessionFactory factory;
    
    @PostConstruct
    public void abre(){
       Configuration cfg = new Configuration();
        cfg.configure();
        
        this.factory = cfg.buildSessionFactory();
    }
    
    public SessionFactory getInstance() {
        return factory;                
    }
    
    @PreDestroy
    public void fecha(){
        factory.close();
    }
    
}
public abstract class GenericDAO<T extends AbstractEntity> implements GenericRepository<T> {
	private final Class<T> classe;
	protected final Session session;

	@SuppressWarnings("unchecked")
	protected GenericDAO(Session session) {
		this.classe = (Class<T>) ((ParameterizedType) getClass()
				.getGenericSuperclass()).getActualTypeArguments()[0];
		this.session = session;
	}

	/* Metodos */
	public void adiciona(T entity) {
		Transaction transaction = session.beginTransaction();
		session.persist(entity);
		transaction.commit();
	}

	public void altera(T entity) {
		Transaction transaction = session.beginTransaction();
		session.update(entity);
		transaction.commit();
	}

	@SuppressWarnings("unchecked")
	public T carrega(Long id) {
		return (T) session.load(classe, id);
	}

	public void remove(T entity) {
		Transaction transaction = session.beginTransaction();
		session.delete(entity);
		transaction.commit();
	}

	@SuppressWarnings("unchecked")
	public List<T> lista_paginada(int first, int max) {
		return this.session.createCriteria(classe).
				setFirstResult(first).
				setMaxResults(max).
				list();
	}
	
	@SuppressWarnings("unchecked")
	public List<T> lista_simples() {
		return this.session.createCriteria(classe).setMaxResults(10).list();
	}
	
	@SuppressWarnings("unchecked")
	public List<T> selectQuery(String sql) {
		return this.session.createSQLQuery(sql)
				.addEntity(classe)
				.setMaxResults(10)
				.list();
	}
}

entendi,

acho que seria legal vc loggar o CriadorDeSession

pra ve se realmente os metodos abre()

e fecha() estão sendo chamados

acredito eu que eles deve ser chamados no começo e no final de um requisição

blz, vou dar uma olhada vlw

Estou com o mesmo problema, começou depois que passei a usar o c3p0, você conseguiu resolver?

Já reparou se este problema acontece em ambiente de produção?

Digo isso porque isso acontece comigo em desenvolvimento, pois no meu caso, usando eclipse, ao salvar o projeto o eclipse compila as classes e o servidor web (tomcat no meu caso) automaticamente se reinicia…

Quando isso acontece, algum tipo de thread não é finalizada… e de tempos em tempos… aparece este stack ai mesmo. Porém, o mesmo não se dá em ambiente de produção…

Teste parando o seu servidor e iniciando manualmente a cada alteração no fonte e veja se isso deixa de acontecer… Se não acontecer é isto que falei mesmo…

Dá uma olhada no log do ambiente de produção e veja se isto também acontece… creio que não… se não… não existe motivo para preocupação…

Abraço