Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Servlet Request Listener Query

 
Reema Patel
Ranch Hand
Posts: 169
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi ranchers,
Pls. consider the following code snippet taken from a tech web site.
I have two queries here:
(1) Is it a must to define the no-args default constructor explicitly? What's the harm if we rely on the Java compiler provided default constructor?

(2) Why do we need a static variable here. We know that there's just one copy of any static variable irrespective of inatances created. But, I wonder if there would be more than one instance of ReqListener class in any scenario.

Thanks,
Reema
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
1) No there is no harm in relying on the default, no-arg constructor.
Remember though, the default constructor is only created if no others exist.
If you create any other constructors, then you must, if you need one, explicitly create the no-arg constructor as well.

2) The amount of code posted is not enough for us to say for sure that only one instance of that listener is going to be created.
[ February 28, 2007: Message edited by: Ben Souther ]
 
Reema Patel
Ranch Hand
Posts: 169
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Ben for the post.
Here's the complete code.


And just one <listener> tag in web.xml


I don't think we need static variable out there?
 
Raghavendra Nittur
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Anyone know the anwer for reema's Query?

Please Let me know.

Reema,

did you get the answer if so post it. am in need of the same.


Regards, Raghav
 
Sunil Vasudevan
Ranch Hand
Posts: 107
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think static is not needed here. There should be only one instance of this listener.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic