简体   繁体   English

分布式Java环境中的资源共享

[英]Resource sharing in a distributed java environment

We have a collection of resources to be distributed to users. 我们有一系列资源可以分发给用户。 Every resource will start in a state <resource_id, READY, timestamp_when_this_resource_expires> 每个资源将以状态<resource_id, READY, timestamp_when_this_resource_expires>

Upon receiving a http request from the user, each web server thread should 收到用户的http请求后,每个Web服务器线程应

  1. find out the resource that is going to expire the soonest, 找出即将过期的资源,
  2. update the state of that resource to <resource_id, IN_USE, timestamp_when_this_resource_expires> 将该资源的状态更新为<resource_id, IN_USE, timestamp_when_this_resource_expires>

I am new to MySQL, I need some help. 我是MySQL的新手,我需要一些帮助。 Two questions 两个问题

  1. How do I make sure two web server threads do not pick same resource and give it to the user . 如何确保两个Web服务器线程不会选择相同的资源并将其提供给用户
  2. I believe, I should use a connection pool in my web server. 我相信,我应该在Web服务器中使用连接池。

Our platform: 我们的平台:

A connection pool won't work out of the box if you have multiple machines serving up resources. 如果您有多台计算机在提供资源,则连接池将无法立即使用。 You could use a clustered cache such as Redis with Sentinel. 您可以使用群集缓存,例如Redis和Sentinel。 This allows you to have keys with a TTL (Time to Live) and also allows for mutual exclusion. 这使您可以使用带有TTL(生存时间)的键,还可以互斥。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM