在 Oracle 过程中实现多线程
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/8213415/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Implementing Multithreading in Oracle Procedures
提问by Incognito
I am working on Oracle 10gR2.
我正在研究 Oracle 10gR2。
And here is my problem -
这是我的问题 -
I have a procedure, lets call it *proc_parent*(inside a package) which is supposed to call another procedure, lets call it *user_creation*. I have to call *user_creation*inside a loop, which is reading some columns from a table - and these column values are passed as parameters to the *user_creation*procedure.
我有一个程序,我们称之为*proc_parent*(在包内),它应该调用另一个程序,我们称之为*user_creation*。我必须在循环中调用*user_creation*,它从表中读取一些列 - 这些列值作为参数传递给*user_creation*过程。
The code is like this:
代码是这样的:
FOR i IN (SELECT community_id,
password,
username
FROM customer
WHERE community_id IS NOT NULL
AND created_by = 'SRC_GLOB'
)
LOOP
user_creation (i.community_id,i.password,i.username);
END LOOP;
COMMIT;
user_Creation procedure is invoking a web service for some business logic, and then based on the response updates a table.
user_Creation 过程正在为某些业务逻辑调用 Web 服务,然后根据响应更新表。
I need to find a way by which I can use multi-threading here, so that I can run multiple instances of this procedure to speed up things. I know I can use *DBMS_SCHEDULER*and probably *DBMS_ALERT*but I am not able to figure out, how to use them inside a loop.
我需要找到一种可以在这里使用多线程的方法,以便我可以运行此过程的多个实例来加快速度。我知道我可以使用*DBMS_SCHEDULER*并且可能使用*DBMS_ALERT*但我无法弄清楚如何在循环中使用它们。
Can someone guide me in the right direction?
有人可以指导我朝着正确的方向前进吗?
Thanks, Ankur
谢谢,安库尔
采纳答案by Incognito
I would like to close this question. DBMS_SCHEDULER as well as DBMS_JOB (though DBMS_SCHEDULER is preferred) can be used inside the loop to submit and execute the job.
我想结束这个问题。DBMS_SCHEDULER 和 DBMS_JOB(虽然 DBMS_SCHEDULER 是首选)可以在循环内使用来提交和执行作业。
For instance, here's a sample code, using DBMS_JOB which can be invoked inside a loop:
例如,这里有一个示例代码,使用可以在循环内调用的 DBMS_JOB:
...
FOR i IN (SELECT community_id,
password,
username
FROM customer
WHERE community_id IS NOT NULL
AND created_by = 'SRC_GLOB'
)
LOOP
DBMS_JOB.SUBMIT(JOB => jobnum,
WHAT => 'BEGIN user_creation (i.community_id,i.password,i.username); END;'
COMMIT;
END LOOP;
Using a commit after SUBMITwill kick off the job (and hence the procedure) in parallel.
在SUBMIT之后使用提交将并行启动工作(以及过程)。
回答by ik_zelf
what you can do is submit lots of jobs in the same time. See Example 28-2 Creating a Set of Lightweight Jobs in a Single Transaction
您可以做的是同时提交大量作业。请参见示例 28-2 在单个事务中创建一组轻量级作业
This fills a pl/sql table with all jobs you want to submit in one tx, all at the same time. As soon as they are submitted (enabled) they will start running, as many as the system can handle, or as many as are allowed by a resource manager plan.
这会在 pl/sql 表中填充您要在一个 tx 中同时提交的所有作业。一旦它们被提交(启用),它们就会开始运行,数量是系统可以处理的,或者是资源管理器计划允许的数量。
The overhead that the Lightweight jobs have is very ... minimal/light.
轻量级作业的开销非常......最小/轻。