Showing posts with label multi threading. Show all posts
Showing posts with label multi threading. Show all posts

Wednesday, May 6, 2015

Servlets vs thread safety


each incoming request to a servlet is handed over to a thread to perform the task.

Read this for more info about how they are handled. http://www.javaworld.com/article/2072798/java-web-development/write-thread-safe-servlets.html

If your servlet implements SingleThreadModel interface, each thread use separate instance of servlet. SingleThreadModel is deprecated, Don't use it.

Thursday, April 30, 2015

Java purpose of AtomicInteger

We can use AtomicInteger to avoid count++ issue in mutli-threading environment.

AtomicInteger provides incrementAndGet() and decrementAndGet() methods which are thread safe.

With use of AtomicInteger, we can solve this problem without using synchronized keyword

more: https://docs.oracle.com/javase/tutorial/essential/concurrency/atomicvars.html

          http://javarevisited.blogspot.in/2012/01/how-to-write-thread-safe-code-in-java.html