Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Does this instantiate the servlet?

 
Meadowlark Bradsher
Ranch Hand
Posts: 109
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello wise and learned folks.
My question to you is:
I am retrieving the name of the class (the servlet) by using getClass().getName() so that I can also have a URL to the source file available within the function of the servlet upon request. My question is does this method instantiate the class whose name it is trying to get? If it does thats not good business for the web container that I am using (especially since it's use is being lent to me for free). Its best to let the container handle the lifecycle of the servlet, other wise porblems may occur so I need to be wary of bad design.
Anybody with some advise on that?
 
Mirko Froehlich
Ranch Hand
Posts: 114
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am not sure I understand exactly what you mean. "getClass.getName()" itself does not instantiate an instance of the class whose name you are determining, but obviously you can only call "getClass()" on an existing object. If you are calling this in a servlet and your question is whether this creates another instance of the servlet, then the answer is no. "getClass()" creates a Class instance, but no instance of the servlet you call it on.
-Mirko
 
Meadowlark Bradsher
Ranch Hand
Posts: 109
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Mirko Froehlich:
If you are calling this in a servlet and your question is whether this creates another instance of the servlet, then the answer is no. "getClass()" creates a Class instance, but no instance of the servlet you call it on.
-Mirko

That's exactly what I was asking. I justed wanted to be sure that I am not instantiating the servlet myself, on top of letting the container do it.
Thanks for your help.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic