我设法使用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)
先感谢您!