PreDestroy (Java EE 5)

Java EE API


javax.annotation Annotation Type PreDestroy


@Documented
@Retention(value=RUNTIME)
@Target(value=METHOD)
public @interface PreDestroy

Implements: Annotation
@Documented
@Retention(value=RUNTIME)
@Target(value=METHOD)

PreDestroy 注释作为回调通知用于各方法,以表示该实例正处于被容器移除的过程中。用 PreDestroy 注释的方法通常用于释放它已持有的资源。除 Java EE 5 中的应用程序客户端容器之外,所有支持 PostConstruct 的容器管理对象都必须支持此注释。应用 PreDestroy 注释的方法必须遵守以下所有标准:该方法不得有任何参数,除非是在 EJB 拦截器 (interceptor) 的情况下,根据 EJB 规范的定义,在这种情况下它将带有一个 InvocationContext 对象;该方法的返回类型必须为 void;该方法不得抛出已检查异常;应用 PreDestroy 的方法可以是 public、protected、package private 或 private;该方法不得是 static;该方法可以是 final;如果该方法抛出未检查异常,则忽略此异常,除非是能够处理异常的 EJB。
英文文档:

The PreDestroy annotation is used on methods as a callback notification to signal that the instance is in the process of being removed by the container. The method annotated with PreDestroy is typically used to release resources that it has been holding. This annotation MUST be supported by all container managed objects that support PostConstruct except the application client container in Java EE 5. The method on which the PreDestroy annotation is applied MUST fulfill all of the following criteria - - The method MUST NOT have any parameters except in the case of EJB interceptors in which case it takes an InvocationContext object as defined by the EJB specification. - The return type of the method MUST be void. - The method MUST NOT throw a checked exception. - The method on which PreDestroy is applied MAY be public, protected, package private or private. - The method MUST NOT be static. - The method MAY be final. - If the method throws an unchecked exception it is ignored except in the case of EJBs where the EJB can handle exceptions.

Since:
1.0
See Also:
PostConstruct, Resource



Submit a bug or feature

Copyright 2007 Sun Microsystems, Inc. All rights reserved. Use is subject to license terms.

一看就知道只有菜鸟才干这么无知的事啦。

PS : 未经我党受权你也可自由散发此文档。 如有任何错误请自行修正;若因此而造成任何损失请直接找人民主席,请勿与本人联系。谢谢!