春季靴队列民意调查

发布于 2025-02-05 21:20:54 字数 293 浏览 6 评论 0原文

我正在使用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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

过期以后 2025-02-12 21:20:58

您可以使用线程同步来保护队列免受并发访问。我在下面添加了一个示例代码。

private static final Queue<T> queue = initQueue();

public void accessQueueA() {
    synchronized(queue) {
       // access queue;
    }
}

You can use thread synchronisation to protect your Queue from concurrent access. I've added a sample code below.

private static final Queue<T> queue = initQueue();

public void accessQueueA() {
    synchronized(queue) {
       // access queue;
    }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文