Slow Java function processing
We have a Java class that we are running in Oracle that takes a lot longer to execute than we expected.
When running the Java in a virtual machine under Eclipse the program runs a lot faster.
The version of Oracle we have is 10.2.0.4 which is running under Windows 64bit.
I have created a small program that demonstrates this - this creates a CSV string with 50,000 elements and then uses the StringTokenizer to access the elements.
Under the Eclipse IDE the program takes 78 milliseconds to execute. Under Oracle it takes 2,422 milliseconds.
The java code is added to a jar and then loaded into Oracle using:-
loadjava -resolve -user our_schema/password@server19:1521:dev3 c:\storeproc\pricing-calculations.jar
The java code is accessed by a function defined as:-
create or replace procedure construct_string
AS LANGUAGE JAVA
NAME 'com.ourapp.services.calculators.TestStringToken.go()';
The actual Java code is:-
----------
public void go() {
long startTime = System.currentTimeMillis();
// Build our csv string - create 50,000 values
StringBuffer data = new StringBuffer();
int tokenCount = 50000;
for(int x = 0; x<tokenCount; x++) {
data.append(x);
data.append(",");
}
data.deleteCharAt(data.length()-1);
// Create tokenizer to traverse the csv
StringTokenizer st = new StringTokenizer(data.toString(), ",");
while(st.hasMoreTokens()) {
String val = st.nextToken();
Double d = new Double(val);
// We would normally add this value to our 2 dimensional array at this point
}
long duration = System.currentTimeMillis() - startTime;
System.out.println(duration);
}
---------
I understand that the code does not really do anything, I have just tried to reduce it as far as possible to demonstrate the speed difference.
The document
Oracle® Database Java Developer's Guide - 10g Release 1 (10.1) at http://download.oracle.com/docs/cd/B14117_01/java.101/b12021/perf.htm#i1006168
does talk about performance and converting the byte code to C, we prefer not to have to do this as our application may live on different platforms.
So, can anyone explain why running Java under Oracle is so much more slower that running the Java under a standalone JVM?
Is there anything I can do that will make this code run faster under Oracle?
Thank you in advance for any help.
David Hudson
Edited by: user7770713 on 18-Nov-2009 07:33