Comments and alternative answers
![]() | Point 3: Isn't it one servlet instance per regist... Point 6: What is the initial size of the pool? Assume there is only one instance of the servlet that implements singlethreadmodel. Does more request imply more instances ( as opposed to more thread when the servlet does not implement SingleThread)? If so, what is the maximum servlet instances? Does it depend on the resource?Author: sharma MR (http://www.jguru.com/guru/viewbio.jsp?EID=4939), Mar 15, 2000 Point 3: Isn't it one servlet instance per registered name of the servlet? |
![]() | Point 2: Each client generates a thread which can call... Does the thread associated with the client request guaranteed to have the sole access and ownership of HttpServletRequest and HttpServletResponse objects? To put it the other way, do I need to synchronize access to these objects (HttpServletRequest and HttpServletResponse)? Author: Tony Biag (http://www.jguru.com/guru/viewbio.jsp?EID=27664), Mar 23, 2000 Point 2: Each client generates a thread which can call doGet() (et al) method. |
![]() | 3. Maybe. It probably depends on the engine implem... 6. The thread pool size is determined by the engine; there should be a config parameter. Every request that comes in while another request is being processed spawns a new instance, up to a certain number of instances. After that, they stall. Again, the numbers are up to the engine. Author: Alex Chaffee (http://www.jguru.com/guru/viewbio.jsp?EID=3), Mar 24, 2000 3. Maybe. It probably depends on the engine implementation. It might be good to check the spec and documentation if your logic depends on it. 2. You definitely always are the only one who has the Request and Response objects, so don't bother synchronizing on them. They're per client request, remember. |
![]() | 2. "Every new client request generates a new ... Author: Alex Chaffee (http://www.jguru.com/guru/viewbio.jsp?EID=3), Apr 3, 2000 2. "Every new client request generates a new thread" -- actually, the servlet engines are free to implement thread pools, which means there's a chance that two successive doGets will happen on the same actual thread. You shouldn't make any assumptions about this either (in case you're tempted to use ThreadLocal variables or some other bad idea :-). |
![]() | ![]() | in case you're tempted to use ThreadLocal variables or some other bad idea :-). Author: Pahl Aakh (http://www.jguru.com/guru/viewbio.jsp?EID=1170988), Apr 16, 2005 Alex, Would you please explain why thie could be a problem? I would think that as long as you assign a new, appropriate, value to ThreadLocal variable before it is used, it will be used properly! A thread will complete the first request-processing before it starts the next one even if reused out of the threadpool, won't it. Thanks |
![]() | Point 3: Reading the "Playing it Smart With Java... This setup sounds good to me, but I have not tried it yet. Any comments?Author: Lars Andersson (http://www.jguru.com/guru/viewbio.jsp?EID=40504), Apr 26, 2000 Point 3: Reading the "Playing it Smart With Java Servlets" by Matthew Ferris and Michael Bogovich in Servlet Central March 1999, the authors suggest a solution where a new instance of a transaction class is created for every client request. Calling this instance's doRun() method would create an execution environment similar to what you get when using the SingleThreadModel. The benefit would be that you can maintain common resources such as connection pools in the servlet's doGet() method before calling the transaction instance's doRun() method. The transaction object can be pooled for performance, or associated with the session if further processing is needed in a later request. |
![]() | How local data in servlet is syncronized Author: Arun Selvaraj (http://www.jguru.com/guru/viewbio.jsp?EID=1105676), Aug 1, 2003 you need not (and should not) synchronize on local data or parameters. And especially you shouldn't synchronize the service() method! (Or doPost(), doGet() et al.) But at any point of time we will have only one instance created for a single servlet.It means that there will be a memory allocation for each and every member of that servlet class only one. So calls to service method will actually use the allocated memory reference. Then how the local variables inside the service will not be allocated at sigle place? And if i declare any other method which is called from service() method in my servlet, will it be thread-safe (or) do i need to syncronize it? Please Clarify. |
![]() | ![]() | Re: How local data in servlet is syncronized Author: Steve Xu (http://www.jguru.com/guru/viewbio.jsp?EID=1107576), Aug 9, 2003 don't confuse the instance variable with the local variable inside service method. instance variable: allocated at the object level, needs to be synchronized. local variable: allocated on the stack of the calling thread, does not need to be synchronized. |
![]() | ![]() | Re: How local data in servlet is syncronized Author: Rishabh Chandra (http://www.jguru.com/guru/viewbio.jsp?EID=1520546), Oct 22, 2009 You should read a bit about how memmory allocation happens in JVM. ALL the OBJECTS are created on the Heap. All the variables or should I say pointers( for C and c++ guys) if they are on the instance then they go on the heap too. All the local variables/pointers go on the stack along with parameters of a method etc. Also JVM has seperate space for final variables and a literal pool for literals and so forth. JVM spec is a good place to start to leant about this. So any variable declared inside the doget or dopost, you do not need to worry about synchronising it. Its local so your thread will get a personal copy of it on its stack. All instance variables are shared by all threads so you need to take care that no two threads access the same data at the same time. you can do this via many thread synchronisation techniques like locks, semaphores, threadLocal, synchronized keyworkd etc etc. |
![]() | synchronize the read only instance variable Author: Deepesh Rastogi (http://www.jguru.com/guru/viewbio.jsp?EID=1119170), Oct 2, 2003 Do I need to synchronize the instance variable/object, which I am trying to keep for read only purposes? I am using two instnce variable, the first is the property from file and the other is an object on which I need to make a method calls to log/store in the database.I do not think both the variable be synchronized... thanks deepesh |
![]() | whats the difference Author: Prashant Jain (http://www.jguru.com/guru/viewbio.jsp?EID=1251496), Jul 2, 2005 what exactly the difference between synchronizing the service method of the servlet and making the servlet to implement singlethreadmodel ? when there just one instance of a servlet then synchronizing the service method would actually sync' every request (thread) calling the servlet. ??? |
No comments:
Post a Comment