on 12-14-2006 1:18 PM
Hi guys,
I am using JCO to connect backend System. If client.connect() is called and for certain reason failed, what should I do to roll back the action so that the system keeps normal. I think client.disconnect is not the solution, because connect is not successful. I encountered this problem, and my portal is totally down, what should I do to avoid this situaltion?
My code is
try{
client.connect();
}
catch (JCO.Exception e){
//WHAT SHOULD BE DONE HERE?
System.exit(1);
}
Thanks in advance!
Regards,
Liying
Hi Liying,
When you do client.connect(); system tries to connect. And there will be only one attempt. And after timeout it will stop trying. Only thing is you can lower down is the timeout period, hence system will try connecting for less time.
The rollout code you can put in catch block. When system isn't able to connet it will throw JCo Exception. You can put your rollout login the catch block.
Regards,
Ashwani
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Liying,
You might be calling client.connect() in some method. Do this..
public boolean connectToSAP()
{
boolean statusFlag = true;
try
{
client.connect();
}
catch (JCO.Exception e)
{
statusFlag = false;
}
}
In your code check the return status from this method and do not execute functions if status is false.
Regards
Abhilash
Hi,
Can you try this code.
class JCOConnector {
private JCO.Client mConnection = null;
// loginParams will settings for connection
public static boolean connect(Properties loginParams) {
boolean returnCode = false;
try {
mConnection = JCO.createClient(loginParams);
long timeBeforeConnecting = System.currentTimeMillis();
mConnection.connect();
long timeAfterConnection = System.currentTimeMillis();
returnCode = true;
} catch (Exception e) {
try {
disconnect();
} catch (Exception e2) {
throw new RuntimeException(e);
}
return returnCode;
}
/**
* To Disconnect from the middleware.
*/
public static boolean disconnect() {
boolean returnCode = false;
if (mConnection != null) { // if connection exists
try {
mConnection.disconnect(); // disconnect from the middleware
returnCode = true;
}catch (Exception e2) {
}finally {
mConnection = null;
}
}else{
returnCode = true;
}
return returnCode;
}
}
Regards,
Ashwani
Hi,
You can also use connection pooling to improve performance.
Use the pdf to get more info
<a href="https://www.sdn.sap.comhttp://www.sdn.sap.comhttp://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/com.sap.km.cm.docs/documents/a1-8-4/tips%20and%20tricks%20for%20sap%20java%20connector%20client%20programming.pdf">JCO Tweeking</a>
Regards
Ashwani
Hi,
Try this code
IWDJCOClientConnection clientCon = WDSystemLandscape.getJCOClientConnection("<WD_MODELDATA_DEST_JCO>");
JCO.Client client= clientCon.getClient();
if(client.isAlive()){
}else{
//Error message
}
Thanks,
Lohi.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
93 | |
10 | |
10 | |
9 | |
9 | |
7 | |
6 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.