java - Servlet context scope vs global variable -
What is the difference between archiving a variable in the ServletContext (if any), and only as a public stable member About keeping classes?
Instead of typing:
// Simplified (!) Int counter = (integer) getServletContext (). GetAttribute ("Counter"); Counter ++; This.getServletContext () SetAttribute ("counter", counter);
Why not only:
// MyServlet public fixed int counter = 0; // MyServlet.counter ++;
(Ignore concurrency issues, please, this is just a dumb example)
What I can tell, both of these options are only under Tommack Behave in a manner. Is there anything better about using the first option?
The web container knows about your servlet reference, but not about your fixed variable which
A separate classloader (this server can be restarted, web application redistribution, or multi-node server), to serve by an application example, two separate requests The reason may be, whatever your argument will have to break the servlet Ndrb will avoid these things as Web container knows about this and it may be serial or keep a general store.
Comments
Post a Comment