cancel
Showing results for 
Search instead for 
Did you mean: 

Open connections between AS Java and AS ABAP when using JRA

Former Member
0 Kudos

Hi, we have a problem with open connections and hope that someone here could give me hint where to find a solution.

The situation is that we open a connection from a Java application to an AS ABAP. In detail, the application first connects to a statefull session bean on the AS Java by RMI. The bean communicates with the associated AS ABAP by the Java Resource Adapter (JRA).

All interactions between all components work correctly. But even after we close the application, manually close of the connections (on side of the AS Java) , remove all created and used session beans there are still open connections between the AS ABAP and the AS Java.

The transaction smgw (Gateway Monitor) shows open connections from jlaunch to our local SAP gateway using the internal communication protocol. Obviously, the established connections are not closed, even when they are open for a week or longer.

After opening 100 connections, the AS ABAP denies additional connection attempts.

We have been able to close all open connections by restarting the AS Java or by restarting the Connector over the Visual Administrator (path: Cluster – Server – Services – Connector Container – “select the right connector” – stop / start).

We have developed our application similar to the tutorial from [https://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/docs/library/uuid/ad09cd07-0a01-0010-93a9-933e247d3ba4]

Can someone explain to us why the connections stay open for so long? Is there no timeout mechanism? Or is there some way to close the connections from our Java application?

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi Hendrik,

the behavior, that the connections get never closed, can be explained by a connection timeout which is rather large. You can change this parameter via the Visual Admin. Therefore, start the Visual Admin, change to the service Connector Container and select the relevant connection factory. You can change the timeout of this connection factory at the tab Managed Connection Factory -> Connection Definition. The connection parameters are described at the official documentation

http://help.sap.com/saphelp_nw70/helpdata/en/e8/23c1e7b5c44530a970972bb526c8fc/frameset.htm.

If an exception is returned from the ABAP side, which is no ABAP exception the connections are closed by the JRA. If an ABAP exception is defined for the function module and this is returned, then the connection is kept open and you have to handle this exception on Java side.

In order to close connections, when the RMI connection from your client to the J2EE Server is cut, I would use the Java statement finally in the methods which are called from outside and would close the connections there.

Best Regards,

Annette

Answers (6)

Answers (6)

Former Member
0 Kudos

Dear Annette,

thank you for your answers and the insights into the functionality of JRA. You have completely solved all my problems. Thanks.

I hope you have a wonderful day.

Hendrik Albers

Former Member
0 Kudos

Dear Annette,

the note 1083348 helped me to solve the problem with the exception. So the close method runs correctly.

Very interesting is the way the close method works. After the call of that method the connection is still shown in the Gateway Monitor (transaction smgw). And also after hours the connection is not completely closed, but when I request a new connection, the connection that is already open is re-used.

So my first question is: Is this behaviour correct?

The second question concerns the behaviour caused by exceptions when using JRA. I tested it to assure the robustness of my application.

The results are also interesting. If I raise an exception on the AS ABAP side, the connection is closed completely. It disappears from the Gateway Monitor.

When I throw a standard exception, for example extending java.io.IOException, on the AS Java the exception is delegated to my application and the connection continues to work normally. If a java.rmi.RemoteException is caught on client side, for example in case of an interrupted connection between my client application and the AS Java, I cannot connect to the bean on the AS Java. This results in a missing call to the close method and in an open connection between both application servers, which is never reused.

I tried to handle this with a call to the close method in the ejbRemove method of the bean, the method which is called when the bean is removed manually or by timeout. But this has no effect.

Is there any other way for closing connections, for example in exception situations?

In consideration of the situation that the connections are open over weeks, I also wonder if there is any kind of timeout mechanism.

Have a Happy Easter!

Former Member
0 Kudos

Hi Hendrik,

the SAP JRA of AS Java 7.0 SPS12 has a bug. If you close the connection, the exception you saw is thrown and the connection is not closed. Please change to an SAP JRA of an SPS greater than 12 or apply note 1083348 where an SAP JRA with the bug fix is attached.

Best Regards,

Annette

Former Member
0 Kudos

First of all I thank you both for responding to my question.

Annette, your hint to close the connection didn’t solve the problem. But it helped me to isolate the cause of the problem.

My program already included the call of the close-method.

In further tests I have reduced the code to the following lines.

public void initContext() throws RemoteException {		
	try {
		InitialContext ic = new InitialContext();
				
		// request a ConnectionFactory from JNDI
		this.connectionFactory = (ConnectionFactory) ic.lookup("deployedAdapters/eis/SAPJRAFactory/nonGlobalTx/eis/SAPJRAFactory");
	
		// create a Connection
		this.connection = connectionFactory.getConnection();
						
		// close the obtained Connection
		this.connection.close();	
		
	} catch (Exception exception) {
		// no exception handling ...
		throw new RemoteException("Exception in initContext() ", exception);
	}
}

The method simply requests a javax.resource.cci.ConnectionFactory, creates a javax.resource.cci.Connection and closes it immediately. During this process, a com.sap.mw.jco.jra.JRA$ResourceException is raised. The exception isn’t propagated to my client application, I found it in the NetWeaver Administrator under “protocols and traces”.

The exception description is:

...
Caused by: com.sap.mw.jco.jra.JRA$ResourceException: Connection handle is already closed and no longer associated with a managed connection
at com.sap.mw.jco.jra.JRA$ConnectionImpl.assertConnection(JRA.java:4080)
at com.sap.mw.jco.jra.JRA$ConnectionImpl.close(JRA.java:4281)
at de.iot_online.msc.ScheduleInteractionsByJRABean.initContext(ScheduleInteractionsByJRABean.java:173)
... 11 more

The exception is thrown during the call of the close-method of the connection.

Do you notice anything in my code that might cause this exception?

Note that I can use the connection to call RFCs successfully if I don't attempt to close the connection.

Soujanya: To understand your response I need to know more about the implementation of the methods openJraConnection() and closeJraConnection(). Both are unknown to me, I guess that you wrote them in your class.

Btw. We are using AS Java 7.0 SPS 12 and Java 1.4.2_12

SB9
Active Participant
0 Kudos

Hi Hendrik,

We had used JRA in our previous project. we did they following to close jra connection.


try
{
  connection = openJraConnection();
  // do all other stuff
  closeJraConnection(connection);
}catch(Exception exp)
{
 // do exception handling;
}
finally
{
  if(connection!=null && connection.isOpen())
  {
    closeJraConnection(connection);
  }
}

Also, make the session bean's transaction type as bean managed


<transaction-type>Bean</transaction-type>

Also release the handle to remote interface of the bean as soon as the work is over. This will cause the bean to be removed from the container.

Thanks,

Soujanya

Former Member
0 Kudos

Hi,

I can imagine two possible reasons why the connections are not closed. First, it could be the case that you have forgotten to close the connections in your application. This means, the method close() was not called for the javax.resource.cci.Connection objects which were used for function module calls. Second, a bug causes this behavior. In this case, please open a message with the error report and enter the version of the Java and ABAP system as information.

Best Regards

Annette Ammann