Why is javax.servlet.SingleThreadModel
deprecated?
Ensures that servlets handle only one request at a time. This interface has no methods. If a servlet implements this interface, you are guaranteed that no two threads will execute concurrently in the servlet's service method.
It is not deprecated. They are still releasing new features on the latest Servlet (like async Servlet). And many of the Java web frameworks are building on top the the Servlet technology.
The javadoc says why. SingleThreadModel
was designed to be an easy solution to low-load concurrency, but it didn't even manage that:
Note that SingleThreadModel does not solve all thread safety issues. For example, session attributes and static variables can still be accessed by multiple requests on multiple threads at the same time, even when SingleThreadModel servlets are used. It is recommended that a developer take other means to resolve those issues instead of implementing this interface, such as avoiding the usage of an instance variable or synchronizing the block of the code accessing those resources.
If it can't achieve what it was designed for, it should not be used.
It's basically a poor way of handling concurrency. Take the state out of your servlet instead, so that the same servlet can be used by multiple threads concurrently. Keeping state in a "pool" of servlet instances, each of which can have state left over from the previous request etc is pretty horrible.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With