Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Programmatically stop Java EE application during initializaton

Is there any Java EE standard (application server cross-compatible) way how to stop the Java EE application during initialization i.e. during running of @PostConstruct anotated method of @Singleton @Startup class?

@Singleton
@Startup
public class Initializer {

    @PostConstruct
    public void checkConfiguration() {
        // stop application here
    }
}

I search for soft way to stop just the application, to whole application server, nothing like System#exit.

like image 632
czerny Avatar asked Jan 09 '23 17:01

czerny


1 Answers

If you throw any kind of RuntimeException (such as IllegalArgumentException for configuration errors) from an @PostConstruct annotated method in an @Startup annotated @Singleton then the entire application will fail deployment.

From §4.8.1 "Singleton Session Bean Initialization" of the EJB 3.2 specification:

If the Startup annotation appears on the singleton session bean class or if the singleton session bean has been designated via the deployment descriptor as requiring eager initialization, the container must initialize the singleton session bean instance during the application startup sequence. The container must initialize all such startup-time singleton session beans before any external client requests (that is, client requests originating outside of the application) are delivered to any enterprise bean components in the application.

This can't be satisfied if initialisation fails.

like image 172
Steve C Avatar answered Jan 16 '23 20:01

Steve C