Java – call the destroy method of the servlet
According to link http://www.xyzws.com/Servletfaq/when-is-destroy-of-servlets-called/20 , one of the reasons for calling the destroy method is that the servlet has not been requested for a long time
I was thinking that there might be some pages that haven't been called for a long time So does this mean that destruction will be summoned and no longer used?
In fact, when I was asked this question in the interview, he told me that the destruction method would only be called when the server was shut down
Appreciate any help
Solution
as far as I am concerned,
In Java servlets, destroy () is not called by programmers However, if it is called, it will be executed The implicit question is, will servlets be broken? No, No The destroy () method should not destroy a java servlet
Destroy () in java servlet means that the content will be executed only when the container decides to destroy the servlet However, if you call the destroy () method yourself, the content is executed and the corresponding process continues For this problem, destroy () is executed and servlet initialization is complete
First call the destroy () method, then delete the servlet from the container, and finally garbage collection The destroy () method usually contains code to release any JDBC connection resources that will not be garbage collected