Is Servlets thread-safe?

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.

Enter your email address to get our daily JOBS & INTERVIEW FAQ's Straight to your Inbox.

Make sure to activate your subscription by clicking on the activation link sent to your email