My Oracle Support Banner

Glassfish Server - JAX-WS Web Service @PostConstruct Annotated Method is Called Twice for a Single Web Service Invocation (Doc ID 1644648.1)

Last updated on OCTOBER 19, 2023

Applies to:

Oracle GlassFish Server - Version 3.1.2 and later
Information in this document applies to any platform.


There is a mismatch in the number of @PostConstruct invocations compared to the number of @PreDestroy invocations when a web service is invoked.

Everytime the above web service is invoked and a new invocation context created, the @PostConstruct annotated method is called.  However, due to this issue that @PostConstruct method is being called twice for each invocation.  For example, if the web service is called 5 times concurrently, there are 10 calls of the @PostConstruct method, and only 5 calls to the @PreDestroy annotated method.

Note that the web service implementations that are created are cached and re-used, so the number of instances that are created, and hence the number of @PostConstruct and @PreDestroy calls invoked will depend on the number of concurrent requests for the web service.

In addition, the @PreDestroy method may not be called under some circumstances, for example when the application server instance is being shutdown.  However, if the application containing the web service is undeployed then the @PreDestroy methods are called, as the specification requires.  This complies with the JAX-WS 2.2 specification, pages 126-127.


To view full details, sign in with your My Oracle Support account.

Don't have a My Oracle Support account? Click to get started!

In this Document

My Oracle Support provides customers with access to over a million knowledge articles and a vibrant support community of peers and Oracle experts.