等待提交的作业在Oracle PL/SQL中完成? [英] Waiting for a submitted job to finish in Oracle PL/SQL?

查看:97
本文介绍了等待提交的作业在Oracle PL/SQL中完成?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在PL/SQL中寻找Java的thread.join()的等效项. IE.我想开始一些作业(线程),然后等待它们完成.

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.

在PL/SQL中这怎么可能?

How is this possible in PL/SQL?

我正在考虑使用dbms_job.submit(我知道它已被弃用). dbms_scheduler也是一种选择.

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

我的代码:

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;

推荐答案

我喜欢Adam Hawkes使用DBMS_SCHEDULER链的解决方案.因为我仍在使用DBMS_JOB并且还没有重写代码,所以不知道.

I like the solution from Adam Hawkes using DBMS_SCHEDULER chains. Didn't know about that since I'm still using DBMS_JOB and not having rewritten code yet.

无论如何...我目前为此使用的解决方案是DBMS_JOB(尽管您可能应该使用DBMS_SCHEDULER,因为如您所述,已弃用DBMS_JOB)和DBMS_ALERT.

Anyway... the solution I currently use for this is a combination of DBMS_JOB (although you should probably use DBMS_SCHEDULER since DBMS_JOB is deprecated as you noted) and DBMS_ALERT.

使用DBMS_JOB创建作业.然后,我们使用dbms_alert.register和dbms_alert.waitany等待作业完成.每个作业完成时都使用dbms_alert.signal.如果作业在父母准备好之前完成并发出信号,则可能会出现问题,但是我敢肯定您可以解决此问题.

Jobs are created using DBMS_JOB. Then we wait for the jobs to complete using dbms_alert.register and dbms_alert.waitany. Each job when it completes uses dbms_alert.signal. There may be a problem if the job completes and signals before the parent is ready but I'm sure you could work around that.

我猜想DBMS_SCHEDULER链可能是您现在应该这样做的方式,但只是为了完整起见添加了我的答案.

I'm guessing that the DBMS_SCHEDULER chains are probably the way you should do this now but am just adding my answer for completeness.

这篇关于等待提交的作业在Oracle PL/SQL中完成?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆