jCaptcha 线程安全吗?
我在一个项目中使用 JCaptcha,并且需要一种无法直接提供的行为。所以我查看了源代码,看看是否可以扩展它以获得我想要的东西,并发现我使用的商店实现(MapCaptchaStore) 使用 HashMap 作为存储。 ..没有同步。
我知道 JCaptcha 不能在集群环境中工作,这不是我的情况,但是同时多个客户端怎么样?商店实现是在外部同步的还是我应该自己推出并确保它正确同步?
蒂亚!
I'm using JCaptcha in a project and needed a behavior that was not directly available. so I looked into the source code to see if I can extend it to obtain what I want and found that the store implementation I use (MapCaptchaStore) uses a HashMap as the store... with no synchronization.
I know JCaptcha does not work in a clustered environment, it is not my case, but how about multiple clients at the same time? Is the store implementation synchronized externally or should I roll my own and make sure it is properly synchronized?
TIA!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
从 MapCaptchaStore 的阅读源来看,此类不是线程安全的。不过,我并不是 100% 愿意支持这个答案,因为同步可能发生在更高的级别(例如,对 MapCaptchaStore 单个实例的所有访问可能会在另一个对象上同步)。
您可以使用 CaptchaStore 的另一种实现。例如,EhcacheCaptchaStore
Judging by the reading source for MapCaptchaStore, this class is NOT thread-safe. I'm not 100% willing to stand behind this answer though, because synchronisation may be happening at a higher level (eg all accesses to a single instance of MapCaptchaStore may be synchronised on another object).
You could use another implementation of CaptchaStore. For example, EhcacheCaptchaStore
验证码存储的基本哈希图实现不同步,这可能会导致一些奇怪的行为。
其他存储是线程安全的,为了简单实现,请使用 FastHashMapCaptchaStore。
Basic hashmap implementation of the captcha store is not synchronized, that could lead to some weird behaviour.
Other stores are thread safe, for a simple implementation use FastHashMapCaptchaStore.
我假设这是因为它被设计为与始终具有多个客户端的 Web 应用程序集成。它也是一个验证码框架,因此他们必须经过人类和计算机客户端的测试。
不过,我仍然建议测试它在多线程环境中是否表现正常。
I'm assuming it is because it has been designed to be integrated with web applications which will always have multiple clients. It's also a CAPTCHA framework so they must have tested with both human and computer clients.
However, I would still recommend testing whether it behaves correctly in a multithreaded environment.