Thread Use in the JavaServer Faces Reference Implementation

By: Derek BerubeWildstar Technologies, LLC.
Last Modified: July 10, 2014

Summary

By default, Sun's reference implementation (RI) for the JavaServer Faces (JSF) framework uses threads.  When running under traditional Java runtime environments, this does not present a problem because threading is allowed.  Unfortunately, applications deployed on the Google AppEngine platform cannot start threads of their own.  This is enumerated in the "Threads" sub-topic of the "Sandbox" section of the "Java Servlet Environment" document published on Google's web site (shown below).


A Java application cannot create a new java.lang.ThreadGroup nor a new java.lang.Thread. These restrictions also apply to JRE classes that make use of threads. For example, an application cannot create a new java.util.concurrent.ThreadPoolExecutor, or a java.util.Timer. An application can perform operations against the current thread, such as Thread.currentThread().dumpStack().

Recommended Solution

The release notes for the JSF 2.0 reference implementation updated with the release of the second beta describes the "com.sun.faces.enableThreading" configuration parameter which, when set to false, tells the framework NOT to use threads.  Adding the following to an application's WEB-INF/web.xml configuration file will stop any attempts by the JSF framework to spawn additional threads.


<!-- Disable use of threading for single-threaded environments such as

     the Google AppEngine. -->

<context-param>

<param-name>com.sun.faces.enableThreading</param-name>
<param-value>false</param-value>
<description>
When enabled, the runtime initialization and default ResourceHandler 
implementation will use threads to perform their functions. Set this 
value to false if threads aren't desired (as in the case of running 
within the Google Application Engine).

Note that when this option is disabled, the ResourceHandler will not 
pick up new versions of resources when ProjectStage is development.
</description>

</context-param>


If the com.sun.faces.enableThreading context parameter is not set to false (or omitted completely from the web.xml configuration file) an application deployed on the Google App Engine will display a number of different errors all caused by the JSF reference implementation's attempts to construct threads.

Copyright © 2011-2014, Wildstar Technologies, LLC.

Comments