I want the container terminate some of the methods of my EJB beans by timeout. I want it just to rallback the transaction and throw an TimeOutException right when method execution takes longer than some specified time but I can't find any ways to do it in EJB.

P.S. The only option which comes to mind is about running a separate thread and terminating it by calling stop method/by using stop-flag inside the thread etc. But I'm afraid that this solution smells very bad and can affect scalability and the other things we want to achieve using EJB.