春季靴队列民意调查
我正在使用Spring Boot(服务器)发布API请求(Android,Raterofit)。 Spring Boot支持多个线程以发布API。
当我完全同时收到多个API请求时,我需要它们异步运行,但是Spring为每个线程启动了一个新线程。
我试图使用队列,然后一个一个一个一个一个一个一个一个逐一的对象,但是队列要么同时进行轮询,要么如果我让线程睡觉,所有线程都完全在此时间内睡觉,则每个对象同时检索。
任何人都可以建议如何一个一个一个慢慢的调查。请注意,所有其他发布请求都需要并发,但是只有此特定的帖子请求才需要此延迟。
I am using Spring Boot (server) to post an API request (Android, retrofit). Spring Boot supports multiple threads to post the API.
When I receive multiple API requests to the server at exactly the same time, I need them to run asynchronously, but Spring launches a new thread for each.
I have tried to use Queues and then to poll the object one by one, however the Queue is either polled at the same time, or if I make the thread sleep, all of the threads sleep for exactly that amount of time, then every object is retrieved concurrently.
Can anyone advise how to poll slowly one by one. Please note, that the concurrency is needed for all other post request, but only this particular post request requires this delay.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用线程同步来保护队列免受并发访问。我在下面添加了一个示例代码。
You can use thread synchronisation to protect your Queue from concurrent access. I've added a sample code below.