La pregunta SCBCD del día: @PreDestroy

(Imagen: Henri Matisse - El postre: Armonía en rojo)

A developer wants to release resources within a stateless session bean class. The cleanup method should be executed by the container before an instance of the class si removed. The deployment descriptor is not used. Wich three statements are correct? (Choose three)

  • The cleanup method may declare checked exceptions
  • The cleanup method must have no arguments and return void.
  • The cleanup method is executed in an unspecified transaction and security context.
  • The developer sholud mark the cleanup method with the @PreDestroy annotation.
  • The developer should mark the cleanup method with the @PostDestroy annotation.
  • The cleanup method is executed in the transaction and security context of the last business method invocation.

Los beans stateless son destruidos (i.e removidos de memoria) por el contenedor cuando estos ya no son necesarios. Este proceso se inicia cuando el evento PreDestroy del bean es disparado. La clase del bean puede registar un método para manejar este evento mediante la anotación @javax.annotation.PreDestroy (la cuarta va, y la quinta no existe xD). Este método puede tener cualquie nombre , pero debe devolver void, no admitir parámetros y no lanzar excepciones checked (la primera no va, pero la segunda sí). La clase bean puede definir sólamente un método @PreDestroy, y este método se utiliza por lo general para realizar operaciones de "limpieza", como cerrar recursos en utilización; que es lo que requiere la pregunta.

Y para terminar, los métodos PreDestroy se ejecutan en contexto transaccional y de seguridad no especificado. Por lo tanto, nos quedamos con la segunda, la tercera y la cuarta.

Pregunta tomada de ExamWorx

Publicar un comentario