Java Web服务JAX-RS多线程:传递信息

Java Web服务JAX-RS多线程:传递信息,java,multithreading,web-services,jersey,stateless,Java,Multithreading,Web Services,Jersey,Stateless,我正在使用以下配置构建基于JAX-RS的web服务: IDE:Eclipse 构建:Maven 部署:Tomcat 使用Jersey 1.8的Jax RS注释 DB:mongoDB 3.0带java驱动程序(本地主机) 客户端:具有多个表单的HTML页面,同时处理GET和POST方法 实际上,该程序是围绕一个带有jax-rs注释的java主servlet开发的。这是我的应用程序处理服务器响应/请求的“入口点”。总体目标是实现一个包含多个html页面的web项目,仅使用JAX-RS控制器 我面

我正在使用以下配置构建基于JAX-RS的web服务:

  • IDE:Eclipse
  • 构建:Maven
  • 部署:Tomcat
  • 使用Jersey 1.8的Jax RS注释
  • DB:mongoDB 3.0带java驱动程序(本地主机)
  • 客户端:具有多个表单的HTML页面,同时处理GET和POST方法
实际上,该程序是围绕一个带有jax-rs注释的java主servlet开发的。这是我的应用程序处理服务器响应/请求的“入口点”。总体目标是实现一个包含多个html页面的web项目,仅使用JAX-RS控制器

我面临一个需求问题,因为用户以html形式发布信息,但这些输入需要在@GET方法中从同一个主servlet中检索。 但是,应用程序不应该使用静态参数检索用户输入:它应该是无状态的(要求),但仍然在多个线程之间共享信息

如何在不使用静态内容(变量userParamList)的情况下完成此操作,如下所示??我想知道这个字段是否可以使用一个简单的get/set,但我知道Jax-RS线程是单独处理的,所以…:(

@Path(“/rest”)
公共类后台应用程序
{
私有静态字符串[]defaultParamList={“时间戳”、“plcVersion”、“udmVersion”、“iotVersion”、“deviceName”、“制造商”、“型号”、“sdk”、“原语名”、“结果”、“状态”};
私有静态字符串[]userParamList={};
私有静态ArrayList容器;
私有静态java.nio.file.Path javaNIOPath;
私有静态MongoClient连接字符串=新MongoClient(“mongodb://localhost:27017");
私人最终MongoClient MongoClient;
公共后端应用程序()
{
此(新MongoClient(connectionString));
}
@职位
@Path(“/postList”)//此上下文开头出现的第一个pot(根目录下的index.html)
@生成(“文本/html”)
公共可查看的getParamList(@FormParam(“textarea”)字符串textarea)引发IOException
{
userParamList=textarea.replaceAll(“\\s*\\n\\s*”,”).split(“,”;//正则表达式过滤所有(多个)空格和回车
返回新的可查看文件(“/query.html”);
} 
@得到
@路径(“/result”)
@生成(“文本/html”)
公共响应getHTML(@Context UriInfo UriInfo)引发IOException
{
MongoDatabase mongoDB=mongoClient.getDatabase(“JSONRepository”);
MongoCollection coll=mongoDB.getCollection(“TestColl”);
container=mongo.getParameters(userParamList、coll、queryParams);
//userParamList在这里是静态的。。。
//拿东西。。。。。
}
}
谢谢你的回答


PS:静态内容可以很好地工作……所以问题更多地集中在Jersey的多线程问题上。

您确定使用这种方法,因为您想要的是类似web应用程序的东西,并且您尝试使用web服务来实现这一点,在同时有多个请求的情况下,您尝试使用静态内容将不起作用事实上:)我的要求是只使用Jax-Rs注释。它将简化整个项目,只需用一种主要方法处理请求。你还在想什么?好的。我改变了我的方式解决了这个问题。现在可以使用jQuery检索来自HTML页面的参数。因此,不再需要在我的JAX-RSservlet中使用静态内容。
@Path("/rest")
public class BackendApp 
{

    private static String[] defaultParamList = {"timestamp","plcVersion","udmVersion","iotVersion","deviceName","manufacturer","model","sdk","primitiveName","result","status"};
    private static String[] userParamList = {};
    private static ArrayList<Document> container;
    private static java.nio.file.Path javaNIOPath;
    private static MongoClientURI connectionString = new MongoClientURI("mongodb://localhost:27017");
    private final MongoClient mongoClient;

    public BackendApp()
    {
         this(new MongoClient(connectionString));
    }

    @POST
    @Path("/postList") // FIRST pot that occurs at the beginning of this context (index.html at the root)
    @Produces("text/html")
    public Viewable getParamList(@FormParam("textarea") String textarea) throws IOException
    {
        userParamList = textarea.replaceAll("\\s*\\n\\s*","").split(","); //   REGEX expression filtering all the (multiple) blank spaces and carriage return
        return new Viewable("/query.html");
    } 

    @GET 
    @Path("/result")
    @Produces("text/html")
    public Response getHTML(@Context UriInfo uriInfo) throws IOException
    {
          MongoDatabase mongoDB = mongoClient.getDatabase("JSONRepository");
          MongoCollection<Document> coll = mongoDB.getCollection("TestColl");
          container = mongo.getParameters(userParamList, coll, queryParams);
          // userParamList is here static...

          // GET STUFF.....

    }
}