PL/SQL 等待 Oracle 中的更新
如何创建 PL/SQL 函数,该函数在指定的超时时间内等待某行的更新,然后返回。
我想要完成的是 - 我有一个长时间运行的进程,它将通过 process_id 将其状态更新为 ASYNC_PROCESS 表。我需要在该过程完成时返回 true/false 的函数,而且我还需要该函数等待该过程完成一段时间,超时返回或在过程完成时立即返回 true。我不想使用 sleep(1 sec),因为在这种情况下我会有 1 秒的延迟。我不想使用 sleep(1 msec),因为在这种情况下我会消耗 cpu 资源(和 1 msec 滞后)。
有经验的程序员有什么好方法可以实现这一点吗?
该函数将从 .NET 调用(因此我需要数据库操作和 .NET/UI 之间的最小延迟)
THNX, 牛肉
How do I create PL/SQL function which waits for update on some row for specified timeout and then returns.
What I want to accomplish is - I have long running process which will update it's status to ASYNC_PROCESS table by process_id. I need function which returns with true/false when this process has completed, but also I need this function to wait some time for this process complete, return on timeout or return imediately with true, when process has completed. I don't want to use sleep(1 sec), because in such case I will be having 1 sec lag. I don't want to use sleep(1 msec), because in such case I am spending cpu resources (and 1msec lag).
Is there a good way how experienced programmer would accomplish this?
That function will be called from .NET (So I need minimal lag between DB operation and .NET/UI)
THNX,
Beef
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我认为在这种情况下最明智的做法是使用 update 在该
ASYNC_PROCESS
表上触发。您还应该查看
DBMS_ALERT
包。以下是该文档的编辑摘录:创建警报:
在表上创建触发器来触发警报:
从您的
.net
代码中,您可以使用调用此内容的内容:请确保阅读有关
:status
和:timeout
功能的文档。I think the most sensible thing to do in this case is to use update triggers on that
ASYNC_PROCESS
table.You should also look into the
DBMS_ALERT
package. Here's an edited excerpt from that doc:Create an alert:
Create a trigger on your table to fire the alert:
From your
.net
code, you can the use something that calls this:Make sure you read the docs for what
:status
and:timeout
do.您应该查看 Oracle高级排队。它提供了您正在寻找的功能。
您可能需要一个单独的队列表,其中 ASYNC_PROCESS 上的触发器插入消息。然后,您可以使用 AQ 函数检索(或等待)队列表中的下一条消息。
You should look at Oracle Advanced Queuing. It offers the kind of functions your looking for.
You'll probably need a separate queue table where a trigger on ASYNC_PROCESS inserts messages. You then use the AQ functions to retrieve (or wait for) the next message in the queue table.
如果您在 C#.NET 中执行此操作,为什么不简单地生成一个工作线程来执行更新(通过 ODAC)?当(看起来)您希望 .NET 进程进行更新调用(在后台)并让主进程收到更新完成通知时,为什么要将责任交给 Oracle?
请参阅此处和此处 为例,尽管 .NET 中有多种方法(委托、事件、异步回调、线程池等)
If you're doing this in C#.NET, why wouldn't you simply spawn a worker thread to do the update (via ODAC)? Why hand the responsibility over to Oracle when (it seems) you want a .NET process to make the update call (in background) and have the main process be notified of its completion.
See here and here for examples, although there are several approaches in .NET for this (delegates, events, async callbacks, thread pools, etc)