Servlets are not thread safe. If you want to make it Servlet as Thread safe, you can implement SingleThreadInterface.
There are two different ways of making a servlet thread safe namely
- By implementing SingleThreadModel:
- By implementing a SingleThreadModel it will be possible to create a Thread safe servlet.There can only be one user at a given point of time.
- Synchornize the part of sensitive code:
We can allow a single user at a given point of time by making that part of the code which is sensitive as synchronized