Hi,
I am running an ejb application with below mentioned configuration:
Server: Glassfish Payara 4.1.1.163
Java: 1.8.0_51
Database: Oracle 10g
Hibernate: 5.1.0.Final
Ejb: 3.2
JPA: 2.1
Persistence.xml
Code:
<?xml version="1.0" encoding="UTF-8"?>
<persistence xmlns="http://java.sun.com/xml/ns/persistence"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd"
version="2.0">
<persistence-unit name="cubecalc-pu" transaction-type="JTA">
<provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>
<jta-data-source>jdbc/myDS</jta-data-source>
<class>com.mypage.domain.MyEntity</class>
<exclude-unlisted-classes>true</exclude-unlisted-classes>
<properties>
<property name="hibernate.dialect" value="org.hibernate.dialect.Oracle10gDialect" />
<property name="hibernate.hbm2ddl.auto" value="update" />
<property name="hibernate.transaction.jta.platform" value="org.hibernate.engine.transaction.jta.platform.internal.SunOneJtaPlatform"/>
<property name="hibernate.id.new_generator_mappings" value="true"/>
<property name="hibernate.transaction.manager_lookup_class"
value="org.hibernate.transaction.SunONETransactionManagerLookup" />
<property name="hibernate.cache.use_second_level_cache" value="true" />
<!-- EhCache -->
<property name="hibernate.cache.region.factory_class"
value="org.hibernate.cache.ehcache.EhCacheRegionFactory" />
<property name="hibernate.cache.use_query_cache" value="false" />
<property name="net.sf.ehcache.configurationResourceName" value="ehcache.xml" />
<property name="debugUnreturnedConnectionStackTraces" value="true" />
<property name="hibernate.connection.release_mode" value="AFTER_STATEMENT" />
</properties>
</persistence-unit>
</persistence>
PersistenceFromContextEjbImpl.java
Code:
@Stateless
public class PersistenceFromContextEjbImpl implements PersistenceFromContextEjb {
@PersistenceContext(unitName = "cubecalc-pu")
private EntityManager manager;
public EntityManager getEntityManager() {
return this.manager;
}
}
JndiBasedPersistenceProvider.java
Code:
public class JndiBasedPersistenceProvider implements PersistenceProvider {
/** The Constant LOGGER. */
private final static Logger LOGGER = LoggerFactory.getLogger(JndiBasedPersistenceProvider.class);
private PersistenceProvider manager;
public EntityManager getEntityManager() {
try {
if (null == this.manager) {
this.manager = this.lookupEjbHelper();
}
if (null != this.manager) {
return this.manager.getEntityManager();
}
} catch (NamingException e) {
throw new InitialisationException("Unable to get the EntityManager from JNDI.");
}
throw new InitialisationException("No Entity Manager found at ");
}
private PersistenceProvider lookupEjbHelper() throws NamingException {
LOGGER.info("Getting new Persistence Helper EJB from JNDI.");
Context ctx = new InitialContext();
return (PersistenceProvider) ctx.lookup("com.mypage.persistence.utils.PersistenceFromContextEjb");
}
}
Database call
Code:
public List<T> find() {
javax.persistence.Query query = this.perform(QueryType.SELECT); //perform method just builds the query
if (null == query) {
return new ArrayList<T>();
}
return query.getResultList();
}
Problem:
When find() method is called, then query is executed and returns the results successfully. But after timeout time (
Connection Leak Timeout - a configuration in glassfish), server prints the following stack trace:
Code:
A potential connection leak detected for connection pool BOE_JDBC_XA_ORA. The stack trace of the thread is provided below :
com.sun.enterprise.resource.pool.ConnectionPool.setResourceStateToBusy(ConnectionPool.java:324)
com.sun.enterprise.resource.pool.ConnectionPool.getResourceFromPool(ConnectionPool.java:758)
com.sun.enterprise.resource.pool.ConnectionPool.getUnenlistedResource(ConnectionPool.java:632)
com.sun.enterprise.resource.pool.ConnectionPool.internalGetResource(ConnectionPool.java:526)
com.sun.enterprise.resource.pool.ConnectionPool.getResource(ConnectionPool.java:381)
com.sun.enterprise.resource.pool.PoolManagerImpl.getResourceFromPool(PoolManagerImpl.java:245)
com.sun.enterprise.resource.pool.PoolManagerImpl.getResource(PoolManagerImpl.java:171)
com.sun.enterprise.connectors.ConnectionManagerImpl.getResource(ConnectionManagerImpl.java:354)
com.sun.enterprise.connectors.ConnectionManagerImpl.internalGetConnection(ConnectionManagerImpl.java:307)
com.sun.enterprise.connectors.ConnectionManagerImpl.allocateConnection(ConnectionManagerImpl.java:196)
com.sun.enterprise.connectors.ConnectionManagerImpl.allocateConnection(ConnectionManagerImpl.java:171)
com.sun.enterprise.connectors.ConnectionManagerImpl.allocateConnection(ConnectionManagerImpl.java:166)
com.sun.gjc.spi.base.AbstractDataSource.getConnection(AbstractDataSource.java:115)
org.hibernate.engine.jdbc.connections.internal.DatasourceConnectionProviderImpl.getConnection(DatasourceConnectionProviderImpl.java:122)
org.hibernate.internal.AbstractSessionImpl$NonContextualJdbcConnectionAccess.obtainConnection(AbstractSessionImpl.java:386)
org.hibernate.resource.jdbc.internal.LogicalConnectionManagedImpl.acquireConnectionIfNeeded(LogicalConnectionManagedImpl.java:84)
org.hibernate.resource.jdbc.internal.LogicalConnectionManagedImpl.getPhysicalConnection(LogicalConnectionManagedImpl.java:109)
org.hibernate.engine.jdbc.internal.StatementPreparerImpl.connection(StatementPreparerImpl.java:47)
org.hibernate.engine.jdbc.internal.StatementPreparerImpl$5.doPrepare(StatementPreparerImpl.java:146)
org.hibernate.engine.jdbc.internal.StatementPreparerImpl$StatementPreparationTemplate.prepareStatement(StatementPreparerImpl.java:172)
org.hibernate.engine.jdbc.internal.StatementPreparerImpl.prepareQueryStatement(StatementPreparerImpl.java:148)
org.hibernate.loader.Loader.prepareQueryStatement(Loader.java:1927)
org.hibernate.loader.Loader.executeQueryStatement(Loader.java:1896)
org.hibernate.loader.Loader.executeQueryStatement(Loader.java:1874)
org.hibernate.loader.Loader.doQuery(Loader.java:919)
org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:336)
org.hibernate.loader.Loader.doList(Loader.java:2610)
org.hibernate.loader.Loader.doList(Loader.java:2593)
org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2422)
org.hibernate.loader.Loader.list(Loader.java:2417)
org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:501)
org.hibernate.hql.internal.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:371)
org.hibernate.engine.query.spi.HQLQueryPlan.performList(HQLQueryPlan.java:216)
org.hibernate.internal.SessionImpl.list(SessionImpl.java:1339)
org.hibernate.internal.QueryImpl.list(QueryImpl.java:87)
org.hibernate.jpa.internal.QueryImpl.list(QueryImpl.java:606)
org.hibernate.jpa.internal.QueryImpl.getResultList(QueryImpl.java:483)
com.mypage.persistence.api.ModelQuery.find(ModelQuery.java:278)
com.mypage.persistence.api.ModelQuery.get(ModelQuery.java:300)
com.mypage.persistence.api.DefaultPersistenceFacade.queryByIdHideDeleted(DefaultPersistenceFacade.java:80)
com.mypage.rest.AbstractRESTController.getServer(AbstractRESTController.java:34)
com.mypage.rest.MultiTenantController.getCubeCalcServer(MultiTenantController.java:261)
com.mypage.rest.MultiTenantController.tenantDetails(MultiTenantController.java:179)
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
java.lang.reflect.Method.invoke(Method.java:497)
org.glassfish.jersey.server.model.internal.ResourceMethodInvocationHandlerFactory$1.invoke(ResourceMethodInvocationHandlerFactory.java:81)
org.glassfish.jersey.server.model.internal.AbstractJavaResourceMethodDispatcher$1.run(AbstractJavaResourceMethodDispatcher.java:144)
org.glassfish.jersey.server.model.internal.AbstractJavaResourceMethodDispatcher.invoke(AbstractJavaResourceMethodDispatcher.java:161)
org.glassfish.jersey.server.model.internal.JavaResourceMethodDispatcherProvider$ResponseOutInvoker.doDispatch(JavaResourceMethodDispatcherProvider.java:160)
org.glassfish.jersey.server.model.internal.AbstractJavaResourceMethodDispatcher.dispatch(AbstractJavaResourceMethodDispatcher.java:99)
org.glassfish.jersey.server.model.ResourceMethodInvoker.invoke(ResourceMethodInvoker.java:389)
org.glassfish.jersey.server.model.ResourceMethodInvoker.apply(ResourceMethodInvoker.java:347)
org.glassfish.jersey.server.model.ResourceMethodInvoker.apply(ResourceMethodInvoker.java:102)
org.glassfish.jersey.server.ServerRuntime$2.run(ServerRuntime.java:326)
org.glassfish.jersey.internal.Errors$1.call(Errors.java:271)
org.glassfish.jersey.internal.Errors$1.call(Errors.java:267)
org.glassfish.jersey.internal.Errors.process(Errors.java:315)
org.glassfish.jersey.internal.Errors.process(Errors.java:297)
org.glassfish.jersey.internal.Errors.process(Errors.java:267)
org.glassfish.jersey.process.internal.RequestScope.runInScope(RequestScope.java:317)
org.glassfish.jersey.server.ServerRuntime.process(ServerRuntime.java:305)
org.glassfish.jersey.server.ApplicationHandler.handle(ApplicationHandler.java:1154)
org.glassfish.jersey.servlet.WebComponent.serviceImpl(WebComponent.java:471)
org.glassfish.jersey.servlet.WebComponent.service(WebComponent.java:425)
org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:383)
org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:336)
org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:223)
org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1681)
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:344)
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:214)
com.mypage.filter.JaafFilter.doFilter(JaafFilter.java:62)
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:256)
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:214)
com.mypage.filter.SessionTimeoutFilter.doFilter(SessionTimeoutFilter.java:71)
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:256)
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:214)
org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:316)
org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:160)
org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:734)
org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:673)
com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:99)
org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:174)
org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:416)
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:283)
com.sun.enterprise.v3.services.impl.ContainerMapper$HttpHandlerCallable.call(ContainerMapper.java:466)
com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:169)
org.glassfish.grizzly.http.server.HttpHandler.runService(HttpHandler.java:206)
org.glassfish.grizzly.http.server.HttpHandler.doHandle(HttpHandler.java:180)
org.glassfish.grizzly.http.server.HttpServerFilter.handleRead(HttpServerFilter.java:235)
org.glassfish.grizzly.filterchain.ExecutorResolver$9.execute(ExecutorResolver.java:119)
org.glassfish.grizzly.filterchain.DefaultFilterChain.executeFilter(DefaultFilterChain.java:284)
org.glassfish.grizzly.filterchain.DefaultFilterChain.executeChainPart(DefaultFilterChain.java:201)
org.glassfish.grizzly.filterchain.DefaultFilterChain.execute(DefaultFilterChain.java:133)
org.glassfish.grizzly.filterchain.DefaultFilterChain.process(DefaultFilterChain.java:112)
org.glassfish.grizzly.ProcessorExecutor.execute(ProcessorExecutor.java:77)
org.glassfish.grizzly.nio.transport.TCPNIOTransport.fireIOEvent(TCPNIOTransport.java:526)
org.glassfish.grizzly.strategies.AbstractIOStrategy.fireIOEvent(AbstractIOStrategy.java:112)
org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.run0(WorkerThreadIOStrategy.java:117)
org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.access$100(WorkerThreadIOStrategy.java:56)
org.glassfish.grizzly.strategies.WorkerThreadIOStrategy$WorkerThreadRunnable.run(WorkerThreadIOStrategy.java:137)
org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:591)
org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.run(AbstractThreadPool.java:571)
java.lang.Thread.run(Thread.java:745)
Server is saying that there is a connection leak in the application.
Can anybody help in me with this issue? Any help would be highly appreciated.