Acquiring and Releasing a Connection
...
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.
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.
3. After a successful function call, the connection to the method releaseClient() is released back into the pool.
4.
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.

mConnection = JCO.getClient (POOL_NAME);
|
System.out.println (mConnection.getAttributes () ); }
catch (Exception ex) { ex.printStackTrace (); } finally { JCO.releaseClient (mConnection); } |
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).
When calling a connection pool, never use the
methods connect() or disconnect() from the class
JCO.Client. For connection pools, the functions are executed by the
PoolManager.
For the complete example program for establishing a connection pool, see: