调用servlet的destroy方法 [英] Calling servlet's destroy method

查看:701
本文介绍了调用servlet的destroy方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

根据链接 http:// www。 xyzws.com/Servletfaq/when-is-destroy-of-servlets-called/20 ,当servlet长时间没有请求时,调用destroy方法的原因之一是 / strong>。

As per the link http://www.xyzws.com/Servletfaq/when-is-destroy-of-servlets-called/20, one of the reason of calling destroy method is when the servlet hasn't got a request in a long time.

我原以为可能会有一些页面长时间没有被调用。那么,这是否意味着销毁将被调用并且它们将不再被使用?

I was thinking there could be some pages that don't get called for a long time. So, does that mean destroy will be called and they will be no longer used?

实际上,我在采访中被问到这个问题,他告诉我,破坏方法只会当服务器关闭时调用。

Actually, I was asked this question in interview and he told me that destroy method will only be called when server is shut down.

感谢任何帮助。

推荐答案

AFAIK,

在java servlet中, destroy()不应该被程序员调用。但是,如果调用它,它就会被执行。隐含的问题是,servlet会被销毁吗?不,它不会。 destroy()方法不应该也不会破坏java servlet。

In java servlet, destroy() is not supposed to be called by the programmer. But, if it is invoked, it gets executed. The implicit question is, will the servlet get destroyed? No, it will not. destroy() method is not supposed to and will not destroy a java servlet.

<$ c的含义$ c> destroy()在java servlet中,内容在容器决定销毁servlet之前执行。但是如果您自己调用 destroy()方法,则会执行内容,然后继续相应的过程。对于这个问题, destroy()被执行,然后servlet初始化完成。

The meaning of destroy() in java servlet is, the content gets executed just before when the container decides to destroy the servlet. But if you invoke the destroy() method yourself, the content just gets executed and then the respective process continues. With respective to this question, the destroy() gets executed and then the servlet initialization gets completed.

<$首先调用c $ c> destroy()方法,然后从容器中删除Servlet,最后进行垃圾回收。 destroy()方法通常包含释放任何资源(如JDBC连接)的代码,这些资源不会被垃圾回收。

destroy() method is invoked first, then Servlet is removed from the container and then eventually garbage collected. destroy() method generally contains code to free any resources like JDBC connection that will not be garbage collected.

这篇关于调用servlet的destroy方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆