Wildfly10 Remote EJB calls to another EJB on another Wildlfy 10 instance leaking jdbc connections
spatwary04 Oct 6, 2016 3:29 PMwe are migrating from jboss 4.2 to wildlfy 10 . We have a app(client) which collects data from another more than one app(servers) using remote calls from slsbs deployed on client to slsbs (stateless session beans ) deployed on these servers.
Below is the code:
Below is sample method how are using it:
private void synctest(TestServer server ) throws Exception
{
Context ejbRootNamingContext=null;
Context context=null;
try
{
context= serviceLocator.getServerContext(server.getHostAddress(), 1199);
ejbRootNamingContext=(Context) context.lookup("java:");
ServerService is = serviceLocator.getService(ejbRootNamingContext, server.getHostAddress(),
IQVMSServerConstants.DEFAULT_JNDI_PORT,
"/ear-filename/ejb-jar-name/ServiceBean!com.test.ServiceRemote",
ServerService.class );
List<TestGroups> groups = is.listAllTestGroups();
// persist the groups in local database.
List<TestGroups2> groups2 = is.listTestGroups2();
// persist the group2s in local database.
catch( Exception exc )
{
logger.log( Level.SEVERE, "Cannot sync groupsfrom server: " + server, exc );
}
finally {
try {
// close the EJB naming JNDI context
ejbRootNamingContext.close();
logger.log(Level.FINEST,"closed ejbRootNamingContext");
} catch (Throwable t) {
logger.log( Level.SEVERE, "unable to close ejbRootNamingContext"+t.getMessage() );
}
/*try {
// also close our other JNDI context since we are done with it too
// context.close(); --- Commented out this code if uncommented getting excpetions . Does not seems to work . Dont know the reason.
} catch (Throwable t) {
// log and ignore
}*/
}
}
Another use case is in the loop of servers:
private void collectusing loop(List<TestServer> server ) throws Exception
{
Context ejbRootNamingContext=null;
Context context=null;
for(TestServer aggrServer : servers)
{
try
{
context= serviceLocator.getServerContext(server.getHostAddress(), 1199);
ejbRootNamingContext=(Context) context.lookup("java:");
ServerService is = serviceLocator.getService(ejbRootNamingContext, server.getHostAddress(),
IQVMSServerConstants.DEFAULT_JNDI_PORT,
"/ear-filename/ejb-jar-name/ServiceBean!com.test.ServiceRemote",
ServerService.class );
List<TestData> testdata= is.listTestData();
// persist the testdatain local database.
catch( Exception exc )
{
logger.log( Level.SEVERE, "Cannot sync datafrom server: " + server, exc );
}
finally {
try {
// close the EJB naming JNDI context
ejbRootNamingContext.close();
logger.log(Level.FINEST,"closed ejbRootNamingContext");
} catch (Throwable t) {
logger.log( Level.SEVERE, "unable to close ejbRootNamingContext"+t.getMessage() );
}
/*try {
// also close our other JNDI context since we are done with it too
// context.close(); --- Commented out this code if uncommented getting excpetions . Does not seems to work . Dont know the reason.
} catch (Throwable t) {
// log and ignore
}*/
}
}
}
serviceLocator:
public Context getServerContext( String host, int port )
throws Exception
{
//In wildfly After reading the doumentation we changed it to use http remoting
Properties clientProp = new Properties();
clientProp.put( "java.naming.factory.initial", "org.jboss.naming.remote.client.InitialContextFactory" );
clientProp.put(Context.URL_PKG_PREFIXES, "org.jboss.ejb.client.naming");
clientProp.put( "java.naming.provider.url", "http-remoting://"+host+":"+port );
clientProp.put(Context.SECURITY_PRINCIPAL, "iq");
clientProp.put(Context.SECURITY_CREDENTIALS, "sunshine");
clientProp.put("jboss.naming.client.ejb.context", true);
clientProp.put("org.jboss.ejb.client.scoped.context","true");
// logger.log(Level.SEVERE, "before setting InitialContext");
return new InitialContext(clientProp);
}
public <T> T getService( Context ctx, String serviceName, Class<T> c )
throws Exception
{
//String serviceNameasejb=serviceName.replaceFirst("/", "");
return c.cast( ctx.lookup( serviceName ) );
}
public <T> T getService( Context ejbcontext,String host, int port, String serviceName, Class<T> c )
throws Exception
{
try{
return getService( ejbcontext, serviceName, c );
}
finally{
}
}
In jboss 4.2 we were creating intialcontext by passing host and port for each servers.
Hashtable<String,String> props = new Hashtable<String,String>();
props.put( "java.naming.provider.url", host + ":" + port );
return new InitialContext( props );
After ruuning a while we get javax.resource.ResourceException: IJ000655: No managed connections available within configured blocking timeout (30000 [ms]).