• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Are there any side effects of calling servlet's init method from its constructor ?

 
Ranch Hand
Posts: 257
Hibernate Oracle Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Are there any side effects of calling servlet's init method from its constructor. ?
 
Ranch Hand
Posts: 453
Google Web Toolkit Hibernate Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
well some points :

1> we should always use the default constructor created by the compiler .
2> the constructor must be a no argument one.

so since we are not overriding the constructor so there is no any constructor from where you will call the init() method.
and if you do override the default constructor it may lead to potential conflicts as init() may be called twice.

av sinha
 
Salil Vverma
Ranch Hand
Posts: 257
Hibernate Oracle Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hey Avi,

we are not overriding the constructor so there is no any constructor from where you will call the init() method.
and if you do override the default constructor it may lead to potential conflicts as init() may be called twice.



As I am taking about overriding the default constructor, init method will definitely be called twice once when the servlet would have been instaciated and the second time by the container. but I could not understand what you mean by potential conflicts ? Could you please explain a bit what type of conflict are you talking about ?
 
Sheriff
Posts: 9707
43
Android Google Web Toolkit Hibernate IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Are you talking about calling the init method with no arguments or with a ServletConfig argument?? Generally the code that is placed in the init method is of such nature that they need to be called once. Whether there will be any side effects or not depends on what is in the code. If you've got a System.out.println Statement in it, then there won't be any side effects, but if you are using a limited resource or some lookup or something, then there might be some side effects...
 
reply
    Bookmark Topic Watch Topic
  • New Topic