如何在网络上互斥? [英] How To Mutex Across a Network?

查看:163
本文介绍了如何在网络上互斥?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个运行在网络上的桌面应用程序,每个实例都连接到同一个数据库.

I have a desktop application that runs on a network and every instance connects to the same database.

那么,在这种情况下,我如何实现一个可在连接到同一数据库的所有正在运行的实例上工作的互斥体?

So, in this situation, how can I implement a mutex that works across all running instances that are connected to the same database?

换句话说,我不要两个以上的实例同时运行相同的功能.如果一个已经在运行该功能,则其他实例不应具有该功能.

In other words, I don't wan't that two+ instances to run the same function at the same time. If one is already running the function, the other instances shouldn't have access to it.

PS:数据库事务无法解决,因为我不想互斥的功能不使用数据库.我之所以提到数据库,只是因为它可用于在运行中的实例之间交换信息.

PS: Database transaction won't solve, because the function I wan't to mutex doesn't use the database. I've mentioned the database just because it can be used to exchange information across the running instances.

PS2:该功能大约需要30分钟才能完成,因此,如果另一个实例尝试运行相同的功能,我想显示一条好消息,即由于计算机"X"已经存在,因此目前无法执行运行该功能.

PS2: The function takes about ~30 minutes to complete, so if a second instance tries to run the same function I would like to display a nice message that it can't be performed right now because computer 'X' is already running that function.

PS3:该功能必须在客户端计算机上处​​理,因此我无法使用存储过程.

PS3: The function has to be processed on the client machine, so I can't use stored procedures.

推荐答案

我认为您正在寻找数据库事务.交易会将您的更改与所有其他客户隔离.

I think you're looking for a database transaction. A transaction will isolate your changes from all other clients.

更新: 您提到该函数当前未写入数据库.如果要对该功能进行互斥,则必须有一些中心位置来存储当前的互斥保持器.数据库可以为此工作-只需添加一个包含当前所有者的计算机名的新表即可.在启动功能之前,请检查该表.

Update: You mentioned that the function doesn't currently write to the database. If you want to mutex this function, there will have to be some central location to store the current mutex holder. The database can work for this -- just add a new table that includes the computername of the current holder. Check that table before starting your function.

不过,我认为您的问题可能令人困惑.互斥对象应该与保护资源有关.如果您的职能不是访问数据库,那么您在保护什么共享资源?

I think your question may be confusion though. Mutexes should be about protecting resources. If your function is not accessing the database, then what shared resource are you protecting?

这篇关于如何在网络上互斥?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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