Win a copy of Java 9 Revealed this week in the Features new in Java 9 forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

EPractice Lab quiz 1 about releasing resource after destroy()  RSS feed

 
Himai Minh
Ranch Hand
Posts: 1509
9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

If the container calls the destroy() method on a servlet, who is responsible for releasing resources?

a.Developer
b. Container
c. Web Server
d. Application Server
Choice A is correct
Resources are not released automatically. If we initialize a connection object in the init() method of servlet, the connection will not be released even after the destroy() method is called. It is up to the developer to release the connection object. But remember, all threads created by this servlet will be done. No more requests will ever be served by this instance. destroy() may be called on the servlet by the container either when all the threads have finished with it or a container defined default timeout has been exceeded.


I think the container will garbage collect some objects after destroy() is invoked. I think the answer should be a and b.
 
Les Morgan
Rancher
Posts: 756
17
C++ Java MySQL Database Netbeans IDE Oracle Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I believe what they are looking at is that you, the developer, still have to dereference the object before it can be GC'd.
 
Joe Harry
Ranch Hand
Posts: 10128
3
Eclipse IDE Mac PPC Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That was a crazy question. I see it this way: "You have to release the resource, the container will garbage collect it"
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!