Home > Back-end >  Tomcat static property sharing multiple requests
Tomcat static property sharing multiple requests

Time:11-12

A static property of a class, for example, the request for the first time to value, the second request this value is still there, this is related to Tomcat's request is thread?
If I want to every request is independent of each other, how to implement (static attributes have global role, can't replace with instance attributes)?

CodePudding user response:

Threadlocal should be able to meet the needs of the lz

CodePudding user response:

The browser cache?

CodePudding user response:

No, it's the background Java value here

CodePudding user response:

reference 1st floor qybao response:
threadlocal should be able to meet the needs of the lz

In fact, I just want to ensure that the front a request with a Tomcat processing threads is one-to-one, behind a request to get in front of the don't request assignment of data at a time

CodePudding user response:

Defined as a common member variables, don't use static

CodePudding user response:

ThreadLocal CurreantString=new ThreadLocal<> (a);
This is ok

CodePudding user response:

ThreadLocal can solve

CodePudding user response:

reference 5 floor qq_43158424 reply:
defined as ordinary member variables, don't use the static

I want to cross class transfer data, can't all through parameter,
Static and examples of use is not the same, not a relationship can take the place of another,

CodePudding user response:

refer to 6th floor KeepSayingNo response:
ThreadLocal CurreantString=new ThreadLocal<> (a);
So you can

This is not a good custom code readability, actually this is not an application layer code should solve the problem, but the web container at startup resources way,
Myself in the work of the development platform, don't come across this kind of problem, is a request corresponding to a handler, request over all resources are released,
  • Related