i'm new in this forum. I've some years of experience in java but i'm not expert in j2ee.
I developed a @Stateless EJB that creates a huge file in file system. After that, when the file is ready, i have to send it via mail.
The EJB has transaction management as BEAN, with explicit begin/commit transaction to avoid server timeout.
But if i call this EJB from the client, the client remains freezed until the file is complete
I would like to start file generation and make the client free immediately. Then, i would like to ask server (polling) to know when the file is ready, then send it via mail.
Could you tell me the best way to resolve this problem?
The client waits until the method it calls is ready, so you have to make sure that method finishes early. One easy way to do this is by calling an @Asynchronous method and let that method do the hard work in some other thread.
Note that if you call a method of the same class, that will ignore any annotations. You'd either have to use another helper bean, or use SessionContext and its getBusinessObject method to get a reference to the same object but with all the JEE annotation-based additions enabled.