Show TOC

Procedure documentationAcquiring and Releasing a Connection Locate this document in the navigation structure

Procedure

  1. If you need a current connection from the connection pool, you can acquire this, execute one or more function calls in the SAP server, and then return (release) the connection to the connection pool. The method getClient() is used to acquire a connection.

  2. If all connections in a pool are assigned and the pool has reached its maximum size, SAP JCo waits for a defined period of time (default value: 30 seconds). If no connection becomes available within this time period, an Exception Message (JCO.Exception.JCO_ERROR_RESOURCE.) is output.

    Note Note

    To change the default value for the wait time, you can use the method setMaxWaitTime(), which is available for PoolManagers as well as for individual JCO.Pool objects. The new value is transferred in milliseconds.

    End of the note.
  3. After a successful function call, the connection to the method releaseClient() is released back into the pool.

Note Note

This normally happens in a finally block, so that the method is always executed, independently of whether or not an exception is output. Otherwise if the connection is not released, this could lead to a shortage of available connections in the connection pool.

End of the note.

Syntax Syntax

Requesting a Connection

  1. mConnection = JCO.getClient (POOL_NAME);
End of the code.

Syntax Syntax

Releasing a Connection

  1. System.out.println (mConnection.getAttributes () );}
  2. catch (Exception ex)   {
  3.    ex.printStackTrace ();
  4. }
  5. finally  {
  6.    JCO.releaseClient (mConnection);
  7. }
End of the code.

Note Note

From an SAP server perspective, a session begins with the call of getClient(), and ends with releaseClient(). If you want to call different RFMs in sequence without any third-party interaction occurring during this time, maintain the connection long enough for the sequence to be executed (each RFM is a separate dialog step in the SAP server).

End of the note.

Note Note

When you call a connection pool, never use the methods connect() or disconnect() from theJCO.Client class. The functions are executed in this case by the PoolManager.

End of the note.

More Information

For the complete example program for establishing a connection pool, see: