Is it possible to stop the execution of a method before completion in a SessionBean?

Robert Castaneda

Stopping the execution of a method inside a Session Bean is not possible without writing code inside the Session Bean. This is because you are not allowed to access Threads inside an EJB, refer to section 18.1.2 of the EJB 1.1 specification.

One possible solution (that requires coding) would be to set the transaction that the Session Bean is running within to be rolled back. To do this, use the setRollBackOnly() method of the javax.transaction.UserTransaction interface. This method would of course require that your Session Bean is using transactions.

If the Session Bean is processing many long running requests then it could provide an optimization by checking the transaction status using the getRollBackOnly() call of the javax.ejb.SessionContext object.