How to avoid "IJ000470: ... trying to use a connection factory that has been shut down..."
12:11 19 Jan 2026

I use Jakarta EE with Wildfly (version 37.0). My database is just for simple statistical numbers, therefore I do not use Hibernate and also no transactions (maybe part of the problem?).

Everything works fine in the beginning. Each minute I write new data to the database. But when I shutdown my appliction, the @PreDestroy method of my @Singleton EJB is called and I try to write the last values from memory to the database.

Unfortunately this ends up in an exception most often:

2026-01-19 16:11:51,309 ERROR [DBStatistic] (ServerService Thread Pool -- 215) An exception occurred during insert value to statistic table 'ds_max'!: java.sql.SQLException: jakarta.resource.ResourceException: IJ000470: You are trying to use a connection factory that has been shut down: java:jboss/jdbc/wsStatisticDS
    at org.jboss.ironjacamar.jdbcadapters@3.0.14.Final//org.jboss.jca.adapters.jdbc.WrapperDataSource.getConnection(WrapperDataSource.java:160)
    at org.jboss.as.connector@37.0.1.Final//org.jboss.as.connector.subsystems.datasources.WildFlyDataSource.getConnection(WildFlyDataSource.java:47)
    at deployment.workspace.ear//de.mypackage.ws_core.util.db.DBStatistic.insertToDs(DBStatistic.java:160)
    at deployment.workspace.ear//de.mypackage.ws_core.util.db.DBStatistic.insertToDsSum(DBStatistic.java:146)
    at deployment.workspace.ear.ws_ui.war//de.mypackage.ws_ui.stats.history.HistoryDataProvider.shutdown(HistoryDataProvider.java:150)
    at deployment.workspace.ear.ws_ui.war//de.mypackage.ws_ui.stats.CurrentDataTimer.shutdown(CurrentDataTimer.java:101)
    at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(Unknown Source)
    at java.base/java.lang.reflect.Method.invoke(Unknown Source)
    at org.jboss.as.ee@37.0.1.Final//org.jboss.as.ee.component.ManagedReferenceLifecycleMethodInterceptor.processInvocation(ManagedReferenceLifecycleMethodInterceptor.java:79)
    at org.jboss.invocation@2.0.1.Final//org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:422)
    at org.jboss.invocation@2.0.1.Final//org.jboss.invocation.InterceptorContext$Invocation.proceed(InterceptorContext.java:509)
    at org.jboss.as.weld.common@37.0.1.Final//org.jboss.as.weld.interceptors.Jsr299BindingsInterceptor.delegateInterception(Jsr299BindingsInterceptor.java:62)
    at org.jboss.as.weld.common@37.0.1.Final//org.jboss.as.weld.interceptors.Jsr299BindingsInterceptor.doLifecycleInterception(Jsr299BindingsInterceptor.java:109)
    at org.jboss.as.weld.common@37.0.1.Final//org.jboss.as.weld.interceptors.Jsr299BindingsInterceptor.processInvocation(Jsr299BindingsInterceptor.java:90)
    at org.jboss.invocation@2.0.1.Final//org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:422)
    at org.jboss.as.ee@37.0.1.Final//org.jboss.as.ee.component.ManagedReferenceReleaseInterceptor.processInvocation(ManagedReferenceReleaseInterceptor.java:39)
    at org.jboss.invocation@2.0.1.Final//org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:422)
    at org.jboss.as.ee@37.0.1.Final//org.jboss.as.ee.component.ManagedReferenceReleaseInterceptor.processInvocation(ManagedReferenceReleaseInterceptor.java:39)
    at org.jboss.invocation@2.0.1.Final//org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:422)
    at org.jboss.as.ee@37.0.1.Final//org.jboss.as.ee.component.ManagedReferenceReleaseInterceptor.processInvocation(ManagedReferenceReleaseInterceptor.java:39)
    at org.jboss.invocation@2.0.1.Final//org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:422)
    at org.jboss.as.ee@37.0.1.Final//org.jboss.as.ee.component.NamespaceContextInterceptor.processInvocation(NamespaceContextInterceptor.java:33)
    at org.jboss.invocation@2.0.1.Final//org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:422)
    at org.jboss.as.ejb3@37.0.1.Final//org.jboss.as.ejb3.tx.CMTTxInterceptor.invokeInOurTx(CMTTxInterceptor.java:237)
    at org.jboss.as.ejb3@37.0.1.Final//org.jboss.as.ejb3.tx.CMTTxInterceptor.requiresNew(CMTTxInterceptor.java:399)
    at org.jboss.as.ejb3@37.0.1.Final//org.jboss.as.ejb3.tx.LifecycleCMTTxInterceptor.processInvocation(LifecycleCMTTxInterceptor.java:51)
    at org.jboss.invocation@2.0.1.Final//org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:422)
    at org.jboss.as.ejb3@37.0.1.Final//org.jboss.as.ejb3.component.interceptors.CurrentInvocationContextInterceptor.processInvocation(CurrentInvocationContextInterceptor.java:24)
    at org.jboss.invocation@2.0.1.Final//org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:422)
    at org.wildfly.concurrency@37.0.1.Final//org.jboss.as.ee.concurrent.ConcurrentContextInterceptor.processInvocation(ConcurrentContextInterceptor.java:28)
    at org.jboss.invocation@2.0.1.Final//org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:422)
    at org.jboss.invocation@2.0.1.Final//org.jboss.invocation.ContextClassLoaderInterceptor.processInvocation(ContextClassLoaderInterceptor.java:60)
    at org.jboss.invocation@2.0.1.Final//org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:422)
    at org.jboss.invocation@2.0.1.Final//org.jboss.invocation.ChainedInterceptor.processInvocation(ChainedInterceptor.java:53)
    at org.jboss.as.ee@37.0.1.Final//org.jboss.as.ee.component.BasicComponentInstance.destroy(BasicComponentInstance.java:108)
    at org.jboss.as.ejb3@37.0.1.Final//org.jboss.as.ejb3.component.singleton.SingletonComponent.destroySingletonInstance(SingletonComponent.java:174)
    at org.jboss.as.ejb3@37.0.1.Final//org.jboss.as.ejb3.component.singleton.SingletonComponent.done(SingletonComponent.java:130)
    at org.jboss.as.ejb3@37.0.1.Final//org.jboss.as.ejb3.component.EJBComponent.stop(EJBComponent.java:586)
    at org.jboss.as.ee@37.0.1.Final//org.jboss.as.ee.component.ComponentStartService$2.run(ComponentStartService.java:61)
    at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source)
    at java.base/java.util.concurrent.FutureTask.run(Unknown Source)
    at org.jboss.threads@3.9.1//org.jboss.threads.ContextHandler$1.runWith(ContextHandler.java:18)
    at org.jboss.threads@3.9.1//org.jboss.threads.EnhancedQueueExecutor$Task.doRunWith(EnhancedQueueExecutor.java:2651)
    at org.jboss.threads@3.9.1//org.jboss.threads.EnhancedQueueExecutor$Task.run(EnhancedQueueExecutor.java:2630)
    at org.jboss.threads@3.9.1//org.jboss.threads.EnhancedQueueExecutor.runThreadBody(EnhancedQueueExecutor.java:1622)
    at org.jboss.threads@3.9.1//org.jboss.threads.EnhancedQueueExecutor$ThreadBody.run(EnhancedQueueExecutor.java:1589)
    at java.base/java.lang.Thread.run(Unknown Source)
    at org.jboss.threads@3.9.1//org.jboss.threads.JBossThread.run(JBossThread.java:501)
Caused by: jakarta.resource.ResourceException: IJ000470: You are trying to use a connection factory that has been shut down: java:jboss/jdbc/workspaceStatisticDS
    at org.jboss.ironjacamar.impl@3.0.14.Final//org.jboss.jca.core.connectionmanager.AbstractConnectionManager.allocateConnection(AbstractConnectionManager.java:777)
    at org.jboss.ironjacamar.jdbcadapters@3.0.14.Final//org.jboss.jca.adapters.jdbc.WrapperDataSource.getConnection(WrapperDataSource.java:152)
    ... 51 more

So, it seems like I try to access the database connection a bit too late!

How can I improve this? Is there and EJB I can define a depedency so that my singleton is destroyed before the database connection is is shut down?

Or am I forced to activate transaction management again? But all my attempts so far always end in other exceptions.

database jakarta-ee database-connection