与泽西岛的多线程 [英] Multithreading with Jersey

查看:103
本文介绍了与泽西岛的多线程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下两个链接似乎相互矛盾。我很快就会信任这些文档:

Here are two links which seem to be contradicting each other. I'd sooner trust the docs:

链接1


在同步处理模式下,服务器上的请求处理默认工作

Request processing on the server works by default in a synchronous processing mode

Link 2


它已经是多线程的。

It already is multithreaded.

我的问题:

哪个是正确的。可以同步和多线程吗?

Which is correct. Can it be both synchronous and multithreaded?

为什么文档会说以下内容?:

Why do the docs say the following?:


如果已知资源方法执行需要很长时间来计算结果,则应使用服务器端异步处理模型

in cases where a resource method execution is known to take a long time to compute the result, server-side asynchronous processing model should be used

如果文档是正确的,为什么默认操作是同步的?对于用户体验,所有请求在客户端javascript上都是异步的,因此服务器端的默认操作也应该是异步的。

If the docs are correct, why is the default action synchronous? All requests are asynchronous on client-side javascript by default for user experience, it would make sense then that the default action for server-side should also be asynchronous too.

如果客户端不需要按特定顺序提供请求,然后谁关心操作的昂贵。是不是所有操作都不应该是异步的?

If the client does not need to serve requests in a specific order, then who cares how "EXPENSIVE" the operation is. Shouldn't all operations simply be asynchronous?

推荐答案


默认情况下,服务器上的请求处理工作正常同步处理模式

Request processing on the server works by default in a synchronous processing mode

每个请求都在一个单独的线程上处理。请求被认为是同步的,因为该请求会保留线程,直到请求处理完毕。

Each request is processed on a separate thread. The request is considered synchronous because that request holds up the thread until the request is finished processing.


它已经是多线程的。

It already is multithreaded.

是的,服务器(容器)是多线程的。对于每个进入的请求,都会从线程池中获取一个线程,并且该请求与特定请求相关联。

Yes, the server (container) is multi-threaded. For each request that comes in, a thread is taken from the thread pool, and the request is tied to the particular request.


如果已知资源方法执行需要很长时间来计算结果,则应使用服务器端异步处理模型

in cases where a resource method execution is known to take a long time to compute the result, server-side asynchronous processing model should be used

是,这样我们就不会占用容器线程。容器线程池中只有很多线程来处理请求。如果我们持有长处理请求,那么容器可能会用完线程,阻止其他请求进入。在异步处理中,Jersey将线程交给容器,并自己处理请求处理本身线程池,直到进程完成,然后将响应发送到容器,然后它可以将响应发送回客户端。

Yes, so that we don't hold up the container thread. There are only so many threads in the container thread pool to handle requests. If we are holding them all up with long processing requests, then the container may run out of threads, blocking other requests from coming in. In asynchronous processing, Jersey hands the thread back to the container, and handle the request processing itself in its own thread pool, until the process is complete, then send the response up to the container, where it can send it back to the client.


如果客户不需要按特定顺序提供请求,那么谁在乎操作的费用。

If the client does not need to serve requests in a specific order, then who cares how "EXPENSIVE" the operation is.

不是真的确定客户在这里与任何事情有什么关系。或者至少在您如何提出问题的背景下。抱歉。

Not really sure what the client has to do with anything here. Or at least in the context of how you're asking the question. Sorry.


所有操作都不应该是异步的吗?

Shouldn't all operations simply be asynchronous?

如果所有请求都很快,则不一定。虽然你可以为它做一个论证,但这需要进行性能测试,并且你可以相互抵制并从那里做出决定。每个系统都不同。

Not necessarily, if all the requests are quick. Though you could make an argument for it, but that would require performance testing, and numbers you can put up against each other and make a decision from there. Every system is different.

这篇关于与泽西岛的多线程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆