cancel
Showing results for 
Search instead for 
Did you mean: 

JCO Function: java.lang.outOfMemoryError

Former Member
0 Kudos

Hello

I made a java program that run localy on my pc.

This program use JCO Function that call a function module in SAPCRM.

The program will extract 16.000 lines but ther was an error: Exception in thread "main" java.lan.OutOfMemoryError.

There is any limitation in the temporary data that I'll extract by jco function call a SAP Function module?

Thanks in advance. Luca

Accepted Solutions (0)

Answers (1)

Answers (1)

Former Member
0 Kudos

Hi Luca,

could you show us a little of your code?

regards

Bogdan

Former Member
0 Kudos

try

{

// Logon to the system with credentials.

mConnection = JCO.createClient(SAPclient,SAPuserid,SAPpassword,SAPlanguage,SAPhost,SAPsys);

mConnection.connect();

mRepository = new JCO.Repository("gwPool", mConnection);

try

{

IFunctionTemplate ftemplate = mRepository.getFunctionTemplate("Z_TESTI_ATTIVITA");

com.sap.mw.jco.JCO.Function function = new com.sap.mw.jco.JCO.Function(ftemplate);

com.sap.mw.jco.JCO.ParameterList input = function.getImportParameterList();

//parametri in input

//input.setValue((String)params.get("CLIENT"), "CLIENT");

input.setValue((String)params.get("RELID"), "RELID");

input.setValue((String)params.get("LANGUAGE"),"LANGUAGE");//<letto dal resultset>

//input.setValue((String)params.get("NAME"), rsetSAP.getString("TDNAME"));//<letto dal resultset>

input.setValue((String)params.get("OBJECT"), "OBJECT");

mConnection.execute(function);

parameterList = function.getExportParameterList();

//System.out.println("Messaggio Ritorno:" + parameterList.getField("MESSAGGIO").getString());

LINES = function.getTableParameterList().getTable("LINES");

//eventuale loop sulle righe della jcoTable.... adesso semplicemente scrive un html con il contenuto della LINES

if(LINES!=null)

LINES.writeHTML(SAPFlowFilePath + "LINES_TableDump.html");

else

System.out.println("LINES nulla!");

}

catch (Exception ex)

{

System.out.println("Caught an exception in JCO call:" + ex.toString());

}

JCO.releaseClient(mConnection);

}

catch (Exception ex)

{

System.out.println("Caught an exception in connect: " + ex.toString());

}

Former Member
0 Kudos

Hi Luca,

Its not a JCO problem first of all.

It seems that the JVM is not able to handle the amount of data that comes back from SAP (as you said it is some 16 thousand records) so i think increasing the JVM heap memory size should solve up the problem.

If you are using SAP WAS then do it from the configtool or else modify the values as follows :

You can change the shell script specifying those params:

java -Xms64m -Xmx512m

where -Xms<size> specifies the initial Java heap size and -Xmx<size> the maximum Java heap size.

I hope this helps you,

Guru.

PS: Reward points for helpfull answers.

Former Member
0 Kudos

Hi Singh

I have use java parameter:

java -D.configuration.path=.\ -Xms500m -Xmx1000m -classpath lib\sapjco.jar;. batch.Scheduler

The program give me an error:

Exception in thread "main" java.lang.OutOfMemoryError: requested 552342560 bytes

for jchar in D:/BUILD_AREA/jdk142-update/ws/fcs/hotspot\src\share\vm\prims\jni.

cpp. Out of swap space?

Thanks in advance

Former Member
0 Kudos

Luca,

Some hints to minimize memory used by JCo.

First, do you really need all these rows? It's hard to imagine that users can navigate in more then several handreds rows, and here you have 16000. Check your RFM, probably you can use some filter-like parameter to narrow search. On other hand, if you need to perform some batch update it is better to do this directly on R/3 side.

Second, probably you do not need all output parameters returned by RFM, especially large structures or tables.

Try do deactivate them, something like:

JCO.Function fn = <...>;
fn.getExportParameterList().setActive(false, "SomeHugeButUnnecessaryTableInOutput")

Valery Silaev

EPAM Systems

http://www.NetWeaverTeam.com

Former Member
0 Kudos

Hi Luca,

As the error says your application requested some half GB of memory space, try giving the Xms value more then that ( say 600 mb ) and then see if it works (provided you machine has enough RAM, should be atleast 1 GB as per your application's memory requirements).

Best regards,

Guru.

ilja_farber
Employee
Employee
0 Kudos

Just an info for all Gurus: it was ALWAYS a general rule to set the -Xms and -Xmx (start and max heap size) to same values in order to avoid the reallocation of the heap on the java process and to avoid the fragmentation on the process heap.

Exception in thread "main" java.lang.OutOfMemoryError: requested 552342560 bytes

for jchar in D:/BUILD_AREA/jdk142-update/ws/fcs/hotspot\src\share\vm\prims\jni.

cpp. Out of swap space?

Means that the JNI Interface is not able to create a temp-copy of the data passed through. Since ca 550 Mb could not be allocated, it was surely a table in an export/import parameter list. If you can/would use tables in the table parameter list, I promise the total performace will increase at aleast by 200% and you would not get out of memory any more.

So you can either to change the ABAP interface or create an ABAP wrapper with an other interface, or you have to send the data in smaller bulks (you told about 16.000 lines, i.e. 16.000 lines take 550 Mb and you need at least 550 Mb for JNI and 550 Mb for java heap => even if you set -Xmx=1300M, you could get OOM. So solution could be to send 2 pieces of data a 8000 lines).

Good luck

ilja_farber
Employee
Employee
0 Kudos

by the way, you would save some memory and increase performance, if you create only ONE instance of JCo Repository. It is really safe and save the resources, since each repository has a cache.