简体   繁体   English

play框架中的每个请求的线程

[英]Thread per request in play framework

I am a J2ee developer and i am new to play framework. 我是一名J2ee开发人员,我是新玩的框架。 I did a thorough research but not able to find any clear documentation on that. 我做了一个彻底的研究,但没有找到任何明确的文件。

The question is, how play handles a request. 问题是,游戏如何处理请求。 Will it creates a thread for every request just like J2ee containers? 它会像J2ee容器一样为每个请求创建一个线程吗?

If it is not Thread per request then what happens if we deploy the play application in Tomcat as war file. 如果它不是每个请求的线程,那么如果我们在Tomcat中将播放应用程序部署为war文件会发生什么。

Play 2.3.x uses Netty under the hood to handle HTTP request. Play 2.3.x使用Netty来处理HTTP请求。 You can learn more about Netty here You will also find informations on the Play documentation : https://www.playframework.com/documentation/2.3.x/ThreadPools 您可以在此处了解有关Netty的更多信息您还可以在Play文档中找到有关信息的信息: https//www.playframework.com/documentation/2.3.x/ThreadPools

First, play2 framework does not support tomcat. 首先,play2框架不支持tomcat。

With play and netty, you don't assign one thread per request. 使用play和netty,您不会为每个请求分配一个线程。 By default you have one thread per core in Play but lets assume that you have only one thread for all requests; 默认情况下,Play中每个核心有一个线程,但我们假设您只有一个线程用于所有请求;

In this architecture one thread is shared by all requests. 在此体系结构中,所有请求共享一个线程。 So the thread handles the first request and when it's idle (it is idle when it calls to db or a url etc.) it begins to handle second request. 因此,线程处理第一个请求,当它处于空闲状态时(它在调用db或url等时处于空闲状态),它开始处理第二个请求。 So the thread does not have to return response for the first request to start the second one. 因此,线程不必为第一个请求启动第二个请求返回响应。

One might think that the system will get too slow with this architecture but it's not since the performance depends on cpu. 有人可能认为系统在这种体系结构上会变得太慢但是因为性能取决于cpu而不是。

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

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