2

I have a problem with threads in my JSF application, maybe somebody could help me.

After the start I run new thread which is making some background operations. This thread is working in while(true)-loop but when there is nothing it can do it calls wait(). It's working in loop because I have to call notify() after some user actions.

So now what I want to acomplish: I would like the thread to inform the main thread that the part of the job is finished, so I can update some elements in UI. Any ideas?

I would also like to display FacesMessage, but it's imposible to do so from another thread (even using Observer pattern)

lotk
  • 384
  • 7
  • 20

2 Answers2

0

Maybe you can solve your problem with asynchronous background work with ICEfaces server side push.
Pleas take a look at http://auctionmonitor.icefaces.org/auctionMonitor/auctionMonitor.jsf for an example of the push technology.

Your background working thread could perform a "push", which will "notify" certain pages to update (partially) and display your message.

Zeemee
  • 10,486
  • 14
  • 51
  • 81
0

You can use JMS to communicate between the thread you've got running and your managed beans, but for the rest you'll need to use one of the push technologies as mentioned above.

You could use the primefaces poll component if that's sufficient, otherwise the only push technology that works with jsf that I know of right now is icefaces push. Primefaces is coming out with a new websocket based push component that looks like it will be really nice, but I don't believe it's due to be finished for a couple of months (it showed up in the latest snapshot, but doesn't really do much yet and only works with jetty8). You could also do your own thing with the comet/atmosphere libraries, but having looked at that myself I can tell you those solutions would be a lot of work on your part, pretty much a custom implementation.

Bill
  • 31
  • 3