This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
If a servlet does NOT implement SingleThreadModel, then the static variable in this servlet is thread safe, otherwise, (if implement SingleThreadModel) the static varialbe is not thread safe. Is it right or not? Thank guys. Eunis
hi eunis, a static variable still can be accessed by different thread by declaring var.ClassName. if you can tell the difference between a static and a non-static, you'll find static variable is the same as a non-static in thread safty senario. tony
Hi, By default, a servlet normally has only one servlet instance per servlet definition. Even if we assume or guarantee that only one servlet instance is available to service requests, concurrent requests will spawn multiple threads, so static servlet variables are not thread-safe. A servlet that implements SingleThreadModel is usually pooled by the container so this situation is not thread-safe for static servlet variables either. -anthony [ March 22, 2002: Message edited by: Anthony Villanueva ]