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.
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
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.
After a successful function call, the connection to the method releaseClient() is released back into the pool.
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.
Syntax
Requesting a Connection
mConnection = JCO.getClient (POOL_NAME);
Syntax
Releasing a Connection
System.out.println (mConnection.getAttributes () );}
catch (Exception ex) {
ex.printStackTrace ();
}
finally {
JCO.releaseClient (mConnection);
}
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).
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.
For the complete example program for establishing a connection pool, see: