jboss
Issue with application where EJB connection is left open and subsequent connections are opened and closed
Is it common or acceptable to keep and ejb connection opened while opening and closing other ejb connections or should connections be closed as soon as the client is done with it and a new one opened for subsequent tasks? I'm currently working on a Swing application that uses EJBs (JBoss AS 7.1.1.final). The application opens an ejb connection (i.e. creates an InitialContext instance) and then uses that InitialContext for common tasks for the as long as the application is left running. There are a number of long running operations where an additional ejb connection (and InitialContext) is created. This connection is used for the single long running process and is then closed. On JBoss, after about the 40th connection is opened and closed I get the exception shown below. 2017 May 15, 16:29:03 INFO - (JBossEJBClient.java:121) initialize - JNDI context initialized. java.lang.IllegalStateException: No EJB receiver available for handling [appName:dtsjboss,modulename:dtsserverejb,distinctname:] combination for invocation context org.jboss.ejb.client.EJBClientInvocationContext#4e692639 at org.jboss.ejb.client.EJBClientContext.requireEJBReceiver(EJBClientContext.java:584) at org.jboss.ejb.client.ReceiverInterceptor.handleInvocation(ReceiverInterceptor.java:119) at org.jboss.ejb.client.EJBClientInvocationContext.sendRequest(EJBClientInvocationContext.java:181) at org.jboss.ejb.client.EJBInvocationHandler.doInvoke(EJBInvocationHandler.java:136) at org.jboss.ejb.client.EJBInvocationHandler.doInvoke(EJBInvocationHandler.java:121) at org.jboss.ejb.client.EJBInvocationHandler.invoke(EJBInvocationHandler.java:104) at com.sun.proxy.$Proxy4.getAuthorities(Unknown Source) at com.apelon.dts.examples.errors.ejb.EjbConnectionNotClosedErrorExample.doTest(EjbConnectionNotClosedErrorExample.java:53) at com.apelon.dts.examples.errors.ejb.EjbConnectionNotClosedErrorExample.bothCasesShouldSucceed(EjbConnectionNotClosedErrorExample.java:34) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:606) at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44) at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15) at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41) at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20) at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:76) at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50) at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193) at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52) at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191) at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42) at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184) at org.junit.runners.ParentRunner.run(ParentRunner.java:236) at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50) at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197) If I run the code below, the case where the ejb connections are used and closed works but the case where a single connection is left open fails with the above stack trace. package com.myCompany.myApp.examples.errors.ejb; import java.util.List; import java.util.Properties; import javax.naming.Context; import javax.naming.InitialContext; import org.apache.log4j.Logger; import org.junit.Test; import com.myCompany.myApp.client.jboss.JBossEJBClient; import com.myCompany.myApp.dao.client.myAppServiceClient; import com.myCompany.myApp.dao.client.myAppServiceClientParams; import com.myCompany.myApp.testing.util.logging.LoggerForIntegrationTests; import com.myCompany.myAppserver.dao.remote.AuthorityDao; import com.myCompany.myAppserver.types.TAuthority; import com.myCompany.install.util.ejb.ejbclient.myAppServiceClientFactory; public class EjbConnectionNotClosedErrorExample { private static Logger logger = LoggerForIntegrationTests.get(); private static final int COUNT = 100; #Test public void bothCasesShouldSucceed() { try { logger.debug("Doing case that works"); doTest(true); logger.debug("Done with case that works."); logger.debug("\n\n\n"); logger.debug("********************* DOING CASE THAT FAILS *********************"); doTest(false); logger.debug("Done with use case that didn't work."); } catch (Exception exp) { exp.printStackTrace(); throw new RuntimeException(exp); } } private void doTest(boolean closeConnection) { myAppServiceClientParams params = myAppServiceClientFactory.getDefaultClientParams(); JBossEJBClient blocker = new JBossEJBClient(); blocker.initialize(params); if (closeConnection == true) { blocker.close(); } int max = COUNT; for (int i = 0; i < max; i++) { myAppServiceClient client = myAppServiceClientFactory.getDefaultClient(); AuthorityDao dao = client.createAuthorityDao(); List<TAuthority> list = dao.getAuthorities(); logger.debug("CONNECTION " + (i + 1) + " ------------------------------------------------"); logger.debug("Got " + list.size() + " authorities."); client.close(); } System.out.println(""); } public void initialize(myAppServiceClientParams params) { this.initialize(params.getHost(), params.getPort(), params.getInstance(), params.getUid(), params.getPwd()); } public void initialize(String host, int port, String instance, String user, String password) { final Properties jndiProperties = new Properties(); String providerURL = "remote://" + host + ":" + port; jndiProperties.put(Context.INITIAL_CONTEXT_FACTORY, org.jboss.naming.remote.client.InitialContextFactory.class.getName()); jndiProperties.put(Context.PROVIDER_URL, providerURL); jndiProperties.put("jboss.naming.client.ejb.context", true); jndiProperties.put("jboss.naming.client.connect.options.org.xnio.Options.SASL_POLICY_NOPLAINTEXT", "false"); // Explicitly specify STARTTLS = false for connecting to Wildfly v10 jndiProperties.put("jboss.naming.client.connect.options.org.xnio.Options.SSL_STARTTLS", "false"); jndiProperties.put(Context.SECURITY_PRINCIPAL, user); jndiProperties.put(Context.SECURITY_CREDENTIALS, password); try { InitialContext ctx = new InitialContext(jndiProperties); ctx.getEnvironment(); } catch (Exception e) { throw new RuntimeException(e); } } } Is this a bug that is specific to JBoss AS 7.1.1.final?
Related Links
Unable to call JAX-WS client deployed on JBoss 7.1.1
I want to make an UDP server/listener that runs in JBoss
Path setting for DLL's in JBOSS 7.1.1
using annotations with struts 2 in jboss not finding actions
Jboss with apache2 : anything called on port 8080 should be redirected to 80
JMX Monitoring Software [closed]
JBoss remote debugging issue
Tomee / OpenEJB migration from JBoss
Call a method after jobss started
JBoss 7.1.1: add rt.jar of jre to classpath
StreamGobbler with javax.resource.spi.work.Work inside an EJB
IllegalStateException: No EJB receiver available for handling
SequenceGenerator error: not a valid function or procedure name
How to develop Liferay project in Eclipsce juno and built it on on Jboss
icefaces-facelets 1.8.2 - Compiler Initialization Error under jboss 4.2
JBoss AS 7 modules: can do a module with all libraries in a directory?