简体   繁体   English

多线程http客户端和tomcat 7

[英]multithreaded http client and tomcat 7

I am confused about how should I handle http sessions in a standalone java app. 我对如何在独立的Java应用程序中处理http会话感到困惑。 Here are the details : 详细信息如下:

The java client connects to 3 tomcat 7 servlets. Java客户端连接到3个tomcat 7 servlet。 When the client boots up, it starts 2 scheduled threads /downloader and uploader/ polling 2 of the servlets every 3mins. 当客户端启动时,它每3分钟启动2个调度线程/ downloader和uploader /轮询2个servlet。 They both retrieve and store the jsessionid cookie in private fields in their respective classes. 他们都检索jsessionid cookie并将其存储在各自类的私有字段中。 This results in 2 sessions in tomcat reused for the lifetime of the webapp. 这会导致在tomcat中有2个会话在webapp的生命周期内被重用。 So far so good. 到现在为止还挺好。

There is a 3rd service /connected to the 3rd servlet/ using multiple instances of a threaded "WebDispather" class which retrieves and stores the session similarly to the above mentioned threads but this time - in a private static field. 使用线程“ WebDispather”类的多个实例,有一个第三服务/连接到第三servlet /,该类类似于上述线程,但这次是在私有静态字段中检索和存储会话。 The dispatcher is heavily used, there might be as many as 150 instances running concurrently depending on the load. 调度程序使用率很高,根据负载的不同,可能有多达150个实例同时运行。 Dispatcher threads hit the servlet ever second or so. 分派器线程每秒钟左右就会到达servlet。

Making the dispatcher sessionid field non static creates a session per instance - not good. 将调度程序的sessionid字段设置为非静态会为每个实例创建一个会话-不好。

What are the implications of having all dispatcher threads bound to the same tomcat http session? 将所有调度程序线程绑定到同一tomcat http会话有什么含义?

Thank you 谢谢


EDIT: although dispather threads a bound to same session the session itself doesn't hold any information. 编辑:尽管dispather线程绑定到相同的会话,会话本身不包含任何信息。 Servlet processes only the request params. Servlet仅处理请求参数。 Ie dispatcher 1: 即调度员1:

localhost/messagecontrol?id=123&state 本地主机/ messagecontrol?id = 123&state

Dispatcher thread 2: localhost/messagecontrol?id=123&state=finished 调度程序线程2:localhost / messagecontrol?id = 123&state = finished

//Servlet processes and forgets id and state // Servlet处理并忘记id和状态

As far as I can see the implications are all client threads will share the same session information, if any information not meant to be shared this will be a bug on your code 据我所知,这意味着所有客户端线程将共享相同的会话信息,如果有任何不希望共享的信息,这将是代码中的错误。

IF you're worried about the number of threads created (performance-wise), consider implementing a thread pool in your code. 如果您担心创建的线程数(性能方面),请考虑在代码中实现线程池

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

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