!--a11y-->
Create New JCO Clients 
JCO clientsare managed in a pool. The pool operates in FIFO (first in, first out) mode. If the number of connections to a destination is not limited, the JCO client service creates new JCO clients when the method getJCOClientPoolEntry() is called and the pool is empty. If the pool is full when a JCO client is released, the JCO client that is in the pool for the longest time is disconnected and overwritten.
With the release() method a JCO client can be released. The method disconnects the client and returns it to the pool. The delete() method disconnects the client but does not return it to the pool.
The number of connections to a certain destination can be limited per user. The pool size is defined per destination in the service.xml file (see chapter Configure the JCO Client Service for more details). By default all pools operate without a limit. If a limit is defined, every user can get as many JCO clients as defined by the limit. The limit is also in effect when the user is logged on to different sessions.
JCO clientsrequested in different sessions do not share the same pool. So the pool does not deliver a JCO clientrequested in session S1 to session S2 and vice versa if a user is logged on with session S1 and S2.
When you call getJCOClientPoolEntry() for a limited destination, a TimeoutException can occur when no more JCO clients are available (the limit has been reached) within a specified time. This timeout is defined in service.xml file. Some version of the overloaded getJCOClientPoolEntry() method allow you to request pool entries by specifying other timeout values.
The HTTP session timeout detects when a session is no longer active. The timeout is maintained by the servlet engine. To set the timeout value, see chapter Configure the JCO Client Service for more details.
If such a timeout occurs, the JCO client service closes all pools and all opened JCO clients from this session. If there are still not released pool entries the delete() method is called to finally release them. The isTimeoutOccurred() method is used to check if a timeout for a pool entry occurred. If a timeout occurred the method returns true. The getTimeoutReason() method returns the reason for the timeout as a String.
If a client executes a RFC call that takes longer than the HTTP session timeout, request the pool entry with a getJCOClientPoolEntry() method that has the parameter lifetime. The lifetime parameter is specified in milliseconds and defines that the JCO client will not be disconnected by the JCO client service before the lifetime period has expired, even if a HTTP session timeout occurs. In other words, the lifetime specifies the time of inactivity of an HTTP session before a pool entry is deleted. It is a way to extend the HTTP session timeout for certain clients.
Pool entries created with the parameter lifetime can be released, deleted or finalized any time, as other pool entries. The default value for the lifetime parameter is 0. Use another value only when it is absolutely necessary to extend the run time for a JCO execution in an inactive HTTP session. If a pool entry still exists although a HTTP session timeout occurred, the method isExpiring() returns the time when the delete() method will be called. When the delete() method is called before that time, the method getTimeoutReason() returns the reason for the timeout.
In the first step, to get a JCO client service instance and a pool entry. If no connection is available, a TimeoutException is thrown. If we received a pool entry, the JCO client can be extracted and used. The following example shows how to get a JCO client.
import com.sapportals.portal.prt.component.AbstractPortalComponent;
import com.sapportals.portal.prt.component.IPortalComponentRequest;
import com.sapportals.portal.prt.component.IPortalComponentResponse;
import com.sapportals.portal.prt.service.jco.IJCOClientPoolEntry;
import com.sapportals.portal.prt.service.jco.IJCOClientService;
import com.sapportals.portal.prt.service.jco.TimeoutException
import com.sap.mw.jco.JCO.Client;
public class JCOComponent extends AbstractPortalComponent
{
public void doContent (IPortalComponentRequest request, IPortalComponentResponse response)
{
IJCOClientService clientService =
(IJCOClientService)request.getService(IJCOClientService.KEY);
IJCOClientPoolEntry poolEntry;
try
{
poolEntry = clientService.getJCOClientPoolEntry("SAP_PLM", request);
}
catch (TimeoutException e)
{
response.write("Currently no connection available. Please try again.");
return;
}
catch (Exception e)
{
response.write("Error obtaining connection: " + e);
return;
}
JCO.Client client;
client = poolEntry.getClient();
// Use the client to make R/3 calls
}
}
