I have h:commandButton on clicking it I want to send email and without waiting navigate to other page. Must I do it asyncronously, if yes how can I do it in jsf? (I don't have EJB @Asynchronous annotation)
Asked
Active
Viewed 68 times
0
-
Send your mail in a separate thread. – May 04 '14 at 19:34
-
@Sujan Sivagurunathan: Thanks, but it is not good idea to spawn thread in JSF backing bean. I read that I must do it by implementing ServletContextListener. Can you give me some examples or good article about it? – Aram Gevorgyan May 04 '14 at 22:20
-
@AramGevorgyan, where did you read that is not a good idea to do that? Do you have any reference? Well, for your case it depends on what you want to achieve. I mean, do you want your view to be notified when the e-mail is properly sent? I think it's not a problem to perform it in a separate thread. – Aritz May 05 '14 at 06:48
-
@XtremeBiker: http://www.coderanch.com/t/622607/JSF/java/thread-bean-jsf here is reference. No, I don't need my view to be notified when e-mail is properly sent – Aram Gevorgyan May 05 '14 at 08:55
-
1Well, I've been surfing though some posts related with this topic like [this](http://stackoverflow.com/questions/533783/why-spawning-threads-in-java-ee-container-is-discouraged/533847#533847) and [this](http://stackoverflow.com/questions/6149919/is-it-safe-to-start-a-new-thread-in-a-jsf-managed-bean). In conclusion, I think you could start a thread, but you've to take care of two things: ensure threads end when user session ends and don't let the user start an unlimited number of threads. You could use java thread pool utils for that. – Aritz May 05 '14 at 09:18
-
@XtremeBiker Thanks for answer, I'll explore and try it. – Aram Gevorgyan May 05 '14 at 09:58