Servlet is multithread by default

To start, see this link to get the basic concepts of servlets.

http://stackoverflow.com/questions/3106452/how-do-servlets-work-instantiation-session-variables-and-multithreading

By default, the servelt is of multi-threaded design, so be careful when using class fields since the servlet is not thread safe. The was SingleThreadModel implementation in Java, but now it is deprecated since it does not solve the multi-thread issue overall. It is better to use local variables on servlets and call the classes on the servlet methods.

See the link here on Class fields and local variables explained.
https://cmsoftwaretech.wordpress.com/2014/10/27/java-basics-local-and-global-variables/

Some links on the servlet multi-thread issue.
http://tutorials.jenkov.com/java-servlets/servlet-concurrency.html
http://stackoverflow.com/questions/7701772/how-does-multithreading-work-for-a-java-servlet

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s