Thanks Bosun.
I think my servlet is not implementing SingleThreadModel interface. So multiple threads will be spun to respond to the incoming requests. If I use synchronized(this) block to prevent global variable from being accessed by multiple threads, will that be enough?
I think that "this" in the brackets is of the current servlet object. If you say that only one instance of the servlet will be created, then the global variable accessed inside that synchronized(this) block will be safe, allowing only one
thread to access the global variable at a time.
But if more than one instances of the servlet will be created, then I am sure that synchronized(this) block will not be safe to protect the global variable from being accessed by other instances(not just "this").
Thanks again, Bosun. Your reply really helped me...
Co-author of SCMAD Exam Guide, Author of JMADPlus
SCJP1.2, CCNA, SCWCD1.4, SCBCD1.3, SCMAD1.0, SCJA1.0, SCJP6.0