Waiting for a submitted job to finish in Oracle PL/SQL?

Posted by vicjugador on Stack Overflow See other posts from Stack Overflow or by vicjugador
Published on 2011-01-04T23:51:15Z Indexed on 2011/01/04 23:53 UTC
Read the original article Hit count: 152

Filed under:
|
|

I'm looking for the equivalent of Java's thread.join() in PL/SQL. I.e. I want to kick off a number of jobs (threads), and then wait for them to finish.

How is this possible in PL/SQL?

I'm thinking of using dbms_job.submit (I know it's deprecated). dbms_scheduler is also an alternative.

My code:

DECLARE
  jobno1 number;
  jobno2 number;
BEGIN

  dbms_job.submit(jobno1,'begin dbms_lock.sleep(10); dbms_output.put_line(''job 1 exit'');end;');
  dbms_job.submit(jobno2,'begin dbms_lock.sleep(10); dbms_output.put_line(''job 2 exit'');end;');

  dbms_job.run(jobno1);
  dbms_job.run(jobno2);

  //Need code to Wait for jobno1 to finish
  //Need code to Wait for jobno2 to finish

END;

© Stack Overflow or respective owner

Related posts about multithreading

Related posts about Oracle