如何使用Java防止Google App Engine中的竞争条件? [英] How to prevent race conditions in Google App Engine using Java?

查看:88
本文介绍了如何使用Java防止Google App Engine中的竞争条件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



在某些情况下,我会发送一封邮件给我的应用程序管理员。然后他们可以登录,验证一些数据,然后自动发送电子邮件给应用程序的所有用户。如何防止两个或更多管理员登录并按下发送按钮的情况?我只希望邮件在这种情况下发送一次。 ://code.google.com/appengine/docs/java/taskqueue/overview.html#Worker_URLs_and_Task_Namesrel =nofollow noreferrer>命名任务。每当单击按钮时将任务添加到队列中,但确保两种情况下的名称都可以防止重复(例如,可以用今天的日期或常量命名)。

因此,如果任务已经排队,您会发现...然后您可以选择要执行的操作。您的处理程序还可以记录此邮件已由管理员执行,并在登录时告诉其他管理员。


I don't know whether race condition is the best word, but I didn't find a better word.

In some situations I send a mail to the administrators of my application. They can then log in, verify some data and then automatically send an email to all the users of the application. How do I prevent the situation where two or more administrators are logged in and both press the send-button? I only want the mail to be send once in that case.

解决方案

I'd say go with named tasks. Add a task to the queue whenever the button is clicked, but ensure the name in both cases will prevent duplicates (you could name it with today's date or a constant, for example).

So if the task is already in queue, you'll find out... you can then choose what action to take. Your handler could also record that this mail has already been actioned by an admin, and tell the other admins so when they log in.

这篇关于如何使用Java防止Google App Engine中的竞争条件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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