简体   繁体   中英

How to execute oracle java stored procedure in parallel

I have a query like this:

select samplePackage.prepareMessage(t.message) as text 
from 
sampleSchema.sampleTable t;

sampleTable has large data (number of rows 30M) prepareMessage is a java stored procedure.

private static String prepareMessage(String message) {
   //do some things...
   return preparedMessage;
}

I'm trying to execute this query in parallel. How can i do it?

Thanks.

I've never tried it with Java function myself. But the approach should be as followos:

Run your query with the PARALLEL hint:

select /*+ PARALLEL(t) */ samplePackage.prepareMessage(t.message) as text 
from sampleSchema.sampleTable t;

To successfully execute the SELECT in parallel, Oracle needs to know that your Java function is safe for that. So you have to declare it either as PARALLEL_ENABLE or provide RESTRICT_REFERENCES.

CREATE OR REPLACE FUNCTION PREPARE_MESSAGE(message IN VARCHAR2) RETURN VARCHAR2 PARALLEL_ENABLE
AS LANGUAGE JAVA
    NAME 'sampleSchema.samplePackage.prepareMessage(Java.lang.String) return Java.lang.String';

The query then becomes:

select /*+ PARALLEL(t) */ PREPARE_MESSAGE(t.message) as text 
from sampleSchema.sampleTable t;

There are further restrictions that apply to the function, eg it may not execute DML statements. Otherwise, a parallel execution isn't possible.

As I said: I haven't tried it with Java. But that's the direction to go.

Update: I've changed the code from using a package to using a function. It should be simpler like this.

使用Oracle的预打包API之一(DBMS_JOB包)将多个作业提交到作业队列,然后并行运行它们。

Why do you want to do it in parallel? What are you going to do with results?

The only think I think of running it in parallel is to execute it in one thread, then database server will return ResultSet . This ResultSet can be argument for threads that will retrieve part of database response (for example each thread will read 1M rows).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM