HomeTagSubmit NotesAsk AnythingLoginSubscribe Us
1. Feel Free to ask and submit anything on and get satisfactory answer
2. Registration is not compulsory, you can directly login via google or facebook
3. Our Experts are looking for yours ?.

java-servlet: What is the difference between single thread model and shynchronizations in servlet?

Please explain the key differences between single thread model and shynchronizations in java.

java x 211
servlet x 20
Posted On : 2014-05-02 16:37:45.0
profile Rishi Kumar - Rishi Kumar


SingleThreadModel is a marker interface which makes sure that you servlet can handle only one request at a time. It is not used frequently. it has it´s own limitation. Synchronization related to thread safe it assures that two threads can not simantaneously access the same resource.

SingleThreadModel is used in server side and Synchronization is used in client side.

SingleThreadModel is used for servlets and Synchronization is used for Multithreading.

It is not recommended to synchronize the service method(or methods dispatched to it) because there could effect on performance in case of servlet.

In the Single Threaded Model, the container synchronizes on the servlet for you and ensures that only one thread can access it at a time. So the servlet can safely assume only one thread will execute its code at a time.

The single thread model means that your servlet should not be multi-threaded. If there are two concurrent requests to your servlet, then two instances of your servlet will be created to process these two requests. You can implement the single thread model by implementing the SingleThreadModel interface in your class. This is just a marker interface. It does not have any methods.

The multi threaded model means that your servlet would be multi-threaded and only one instance would be created. Multiple concurrent requests can be served by the same instance but in different threads. You can implement the multi threaded model by not implementing the SingleThreadModel interface in your servlet class that´s it.

Posted On : 2014-05-02 18:03:59
Satisfied : 2 Yes  0 No
profile Saksham Kumar - Saksham Kumar
Reply This Thread

Post Answer
Please Login First to Post Answer: Login login with facebook -