Java Servlet Technology

Concurrent access can arise in several situations in a servlet application:
1. Multiple web components accessing objects stored in the web context.
2. Multiple web components accessing objects stored in a session.
3. Multiple threads within a web component accessing instance variables. A web container will typically create a thread to handle each request. To ensure that a servlet instance handles only one request at a time, a servlet can implement the SingleThreadModel interface. If a servlet implements this interface, no two threads will execute concurrently in the servlet’s service method. A web container can implement this guarantee by synchronizing access to a single instance of the servlet or by maintaining a pool of web component instances and dispatching each new request to a free instance. This interface does not prevent synchronization problems that result from web components’ accessing shared resources, such as static class variables or external objects.

猜你喜欢

转载自blog.csdn.net/zhangmagle125/article/details/56676958