How do you make servlet thread safe?

How do you make servlet thread safe?

Postby Rose » Thu Feb 07, 2013 2:07 am

How do you make servlet thread safe?
Rose
 
Posts: 20
Joined: Tue Jan 29, 2013 5:16 am

Re: How do you make servlet thread safe?

Postby Kishan » Thu Feb 07, 2013 5:37 am

Servlets are multi threaded programs. One servlet object handles any number of requests.

Each request is processed under separate thread so servlet object being used by many threads at a time.

To make servlet as thread safe:
#1 Implement SingleThreadModel interface, servlet process one request at a time. This will degrade performance. This approach is not recommended.
#2 Try to use local variables. When use shared/instance variable make sure those are thread safe.
Kishan
 
Posts: 191
Joined: Tue Jan 29, 2013 4:21 am


Return to Servlets

Who is online

Users browsing this forum: No registered users and 1 guest

cron