• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Command Link, launch a long proccess

 
Yeray Santana Borges
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Is possible use a commandlink to launch an asynchronous process?. I have a web page that call an EJB. I need that the user press a button in the jsf web page, this page must call to my ejb and return the control to the user. My ejb have a very long process and the user can't wait until my ejb finalize.

JSF --> call ejb session bean ---> session bean running a long process
|
return the control to the user <---
immediately

I am using sun one 8.2 and tomahawk. Maybe there are a component (icefaces,trinidad ... ) that can i use to call to my facade and just returned to user control while my ejb is doing a long work.

Can you help me?

Thanks
 
Bauke Scholtz
Ranch Hand
Posts: 2458
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Spawn a separate thread for the long running process. If you want user notification, consider ajax poll.
 
Yeray Santana Borges
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Bauke,

Is possible open a new thread in my backing bean on a action listener method?

I thougth that open a thread in a j2ee envoroment is very dangerous ... i will try it. Maybe open it in a backed bean method no is a problem beacuse is still outside of ejb container.

thanks
 
Bauke Scholtz
Ranch Hand
Posts: 2458
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can just create a thread everywhere you want like as you create a class. In this case just create a class extending Thread or implementing Runnable and run it.

It is only dangerous if you code it the bad way.
 
Yeray Santana Borges
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi again Bauke,

My code its running perfect in this moment. Thanks for your suggestion, in the action listener i create a new thread with my runneable class, and works fine without problems.
 
Yeray Santana Borges
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi again, one question more about this post,

I have a ejb, that is called from a jsf page and this ejb (session bean) run a long process. Have the web container a time out for long process that take in the ejb container?.


I have this escenario for launch a long process in backgroung from a command link:

JSF command link ---> action listener in the session backed bean for that jsf page --> invoke an application backed bean that open a new thread and the control is returned to the user after myThread.starts()--> the new thread in run method invoke a session ejb bean that execute a long process --> my ejb finish the long process --> myThread finish too.

I dont know if is possible that the web container close the connection opened in myThread due to the process is very long. I think that because the thread is open in an application backed bean, there is no time out and if the proccess spend 2 hours, my thread is running 2 hours too.


Thanks
[ September 08, 2008: Message edited by: Yeray Santana Borges ]
 
Tim Holloway
Saloon Keeper
Posts: 18302
56
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Bauke Scholtz:
You can just create a thread everywhere you want like as you create a class. In this case just create a class extending Thread or implementing Runnable and run it.


Not so. In fact, in EJBs in particular you are forbidden to spawn threads per the EJB spec.

In webapps, usually the best place to spin off a thread is from the init method of a dummy servlet (one that has no GET/POST handlers) and have the transactional parts of the system communicate with that thread. Almost any other approach ends up being one of those "Bad Ways".

You can't spin off a thread in the Get/Post handler of a servlet - or a JSF backing bean (usually) or a Struts Form or Action either. That's because you can't leave anything dangling after the HTTP response has been sent, and since the primary purpose of adding the overhead threading is to run something that takes too long to do inline, you'd be wasting time and effort.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic