cancel
Showing results for 
Search instead for 
Did you mean: 

Keeping JCO context in java servlet

Former Member
0 Kudos

Hello guys,

I'm trying to develop a java class that connects a web system (made in struts) with a SAP backend.

i want that class to offer a Jco Destination always opened and with it's context opened (JCoContext.begin(conn)). if I achieve this then i can preload my SAP rfc's with data so that they run way faster (rather than fetching the data all over again with each rfc request).

The problem is that i read that the context i desire to keep always opened (so it can give me the statefulness i need) will close if the thread of execution ends (even if i dont issue the JCoContext.end(conn) command.

i'm thinking that maybe a servlet will do. Offering my class as a servlet, but i have my doubts since i think that every request to the servlet will be a separate thread, hence, closing my desired context.

What do you guys think? Is there another way to achieve this?

Accepted Solutions (1)

Accepted Solutions (1)

MarkusTolksdorf
Product and Topic Expert
Product and Topic Expert
0 Kudos

Hi Fernando,

in this case, you should introduce or search the web for a deployable that registers a SessionReferenceProvider that integrates with the session management of the servlet container. Do not include it in your application. Runtime embedding components should not be part of applications - separation of concerns. See also the JavaDoc of the package com.sap.conn.jco.ext. As there canbe only one such component, a JCo application should never bring its own with its application deployable.. In case such a SessionReferenceProvider implementation is registered, thread switches don't hurt and your JCoContext will survive thread ends and will only be closed automatically in case the servlet container session it belongs to has ended.

Best regards,

Markus

P.S.: It's JCoContext.begin(destination). Do not treat a destination like a connection, it is not a connection. It represents an execution target and opens connections if needed, but it is not a connetion

Answers (1)

Answers (1)

former_member193379
Active Contributor
0 Kudos

Hi Fernando,

In addition to Markus, com.sap.conn.jco.ext.JCoSessionReference interface is  a reference to a sessionin run time which registered a com.sap.conn.jco.ext.SessionReferenceProvider using ID associated with JCoSessionReference.

Thanks,

Hamendra