How to set timeout on an EJB method (in a stateless bean)

I have a session with a stateless bean and one method takes 6 minutes to return the result, which caused me to get a "timeout" exception. I noticed the timeout is already set in wildfly standalone.xml or in persistence.xml file

<session-bean>
   <stateful default-access-timeout="12000" cache-ref="simple" passivation-disabled-cache-ref="simple"/>
   <singleton default-access-timeout="12000"/>
</session-bean>

      

or

<property name="javax.persistence.query.timeout" value="120000" />

      

but this is only for state beans. How do I set a timeout for one method in a stateless bean?

+3


source to share


1 answer


I tried the following annotation and it seems to work:



    @AccessTimeout(value = 15, unit = TimeUnit.MINUTES)
    @Override
    public void myMethod() {
        //do something
    }

      

+1


source







All Articles