Is servlet destroy () called first or finalize ()?

In the servlet, destroy () is called before or after finalize ()?

+3
source share
5 answers

destroy () is called first. destroy () will be called by the servlet container during servlet shutdown. finalize () is called by the JVM before the garbage collector announces objects (and cannot be called at all).

+11
source

In addition, finalize () may or may not be called. Never rely on it.

+3
source

finalize() , . destroy() , .

0

5

  • INIT()
  • service() → doGet() doPost()
  • ()
  • ()
0

If you want to free resources at a specific time, do not depend on external code, such as a servlet container or JVM, to do this. Make your resource allocation and allocation as clear as possible. Disgusting errors may result from external code to clear after you.

-1
source

Source: https://habr.com/ru/post/1710984/


All Articles