Joi*_*ayo 0 java rest multithreading
我设法使用eclipse构建一个小型REST API.以下代码有效:
@Path("Info")
public class Rest {
@POST
@Path("/stats/{j}")
@Produces("application/json")
public Response Status(@PathParam("j") String j) throws JSONException{
JSONObject jsonObject = new JSONObject();
String status = j;
.
.
return Response.status(200).entity(result).build();
}
}
Run Code Online (Sandbox Code Playgroud)
你能告诉我如何使它成为多线程吗?我知道什么是多线程但我需要一些关于如何创建这个代码作为多线程的输入.正在考虑创建另一个实现Runnable的类:
class Demo implements Runnable {
.
.
}
Run Code Online (Sandbox Code Playgroud)
然后,在我的函数Status(@PathParam("j")String j)中,我创建了一个Demo类的对象,例如:
public Response Status(@PathParam("j") String j) throws JSONException{
Demo newThread = new Demo();
JSONObject jsonObject = new JSONObject();
String status = j;
.
.
return Response.status(200).entity(result).build();
}
}
Run Code Online (Sandbox Code Playgroud)
先感谢您!
它已经是多线程的.
将应用程序部署到应用程序服务器(如Jetty或Tomcat)时,应用程序的线程池将确定将使用多少线程来提供Web请求.每次用户针对您的控制器方法发出新的Web请求时,都将使用应用程序服务器线程池中的一个可用线程.
| 归档时间: |
|
| 查看次数: |
7198 次 |
| 最近记录: |