is it a good practice to have static blocks and constructor in servlets. if both are used, what issues might be faced by the servlet in terms of concurancy.
I think it won't have any issues with regards to concurrency. Container make sure that servlets are ready to serve any request after being properly initialized.
Neeraj Vij wrote:what will happen, if I the example given uses the constructor and static blocks?
Reason is when you have a static (class level) variable when multiple threads executed in a given servlet instance you will have all sorts of concurrency issues and that's why you should avoid that.
I just wrote a small servlet for constructors usage-
if we don't want to use a ServletConfig object, it is fine to use a public no-arg constructor. Constructor was inviked first and then the init() method.
I want to know the risks/disadvantage of using constructors in servlet. if any?