如何使用Java防止Google App Engine中的竞争条件?

编程入门 行业动态 更新时间:2024-10-26 05:17:40
本文介绍了如何使用Java防止Google App Engine中的竞争条件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

在某些情况下,我会发送一封邮件给我的应用程序管理员。然后他们可以登录,验证一些数据,然后自动发送电子邮件给应用程序的所有用户。如何防止两个或更多管理员登录并按下发送按钮的情况?我只希望邮件在这种情况下发送一次。 ://code.google/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中的竞争条件?

本文发布于:2023-10-23 19:46:05,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1521832.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:如何使用   条件   竞争   Java   App

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!