FacesContext throws IlegalStateException on renderResponse() method call

Hi,

I require to implement a functionality of a timer when a page loads up.

I created a PhaseListener where a thread is created in the afterPhase() method when the Phase is RenderResponse.

I created another thread in the same method which waits for the first thread to complete.

Both the threads are synchronised on the FacesContext instance.

However, when the second thread gets the control and calls the facesContext object's renderResponse(), I get an IllegalStateException.

I decompiled the FacesContextImpl class where there is a boolean variable called 'released' which is set to true in release() method. And the renderResponse throws an IllegalStateException if this variable evaluates to true.

I tried FacesContext.getCurrentInstance().renderResponse() as well, but it gives me a NullPointerException.

Please help me out on this. I am new to JSF and I understand there might be fundamental flaws in my design as well. If there is any other way to implement this functionality, please do let me know.

Thanks in advance. Cheers !

[1100 byte] By [cnandisha] at [2007-11-27 11:39:45]
# 1

To the best of my knowledge, the FacesContext instance is specific to each request (despite being available via a static method). It is likely that the implementation uses a ThreadLocal object to accomplish this. So saving an instance in another thread is not a good strategy.

I would use another object for the threads to synchronize on and try to limit JSF operations to the thread responding to the request.

OTOH, I would question what you are doing; if you really only have one other thread and the request thread blocks waiting for it to complete, do you really need another thread? Also, in terms of JEE, I imagine that a session EJB might be a better fit -- that way the application server is managing the threads and you have the option in the future of moving the work onto another server or servers.

RaymondDeCampoa at 2007-7-29 17:27:59 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...