Skip to content

Commit

Permalink
Fix problem with JMX triggered parallel application init reported on …
Browse files Browse the repository at this point in the history
…users list

git-svn-id: https://svn.apache.org/repos/asf/tomcat/trunk@1752737 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information
markt-asf committed Jul 14, 2016
1 parent 628c21b commit cec6459
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 25 deletions.
37 changes: 13 additions & 24 deletions java/org/apache/catalina/core/StandardWrapper.java
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -521,33 +521,22 @@ public void setServletName(String name) {




/** /**
* @return <code>true</code> if the servlet class represented by this * Does the servlet class represented by this component implement the
* component implements the <code>SingleThreadModel</code> interface. * <code>SingleThreadModel</code> interface? This can only be determined
* once the class is loaded. Calling this method will not trigger loading
* the class since that may cause the application to behave unexpectedly.
*
* @return {@code null} if the class has not been loaded, otherwise {@code
* true} if the servlet does implement {@code SingleThreadModel} and
* {@code false} if it does not.
*/ */
public boolean isSingleThreadModel() { public Boolean isSingleThreadModel() {

// If the servlet has been loaded either singleThreadModel will be true
// Short-cuts // or instance will be non-null
// If singleThreadModel is true, must have already checked this
// If instance != null, must have already loaded
if (singleThreadModel || instance != null) { if (singleThreadModel || instance != null) {
return singleThreadModel; return Boolean.valueOf(singleThreadModel);
} }

return null;
// The logic to determine this safely is more complex than one might
// expect. allocate() already has the necessary logic so re-use it.
// Make sure the Servlet is loaded with the right class loader
ClassLoader oldCL = null;
try {
oldCL = ((Context) getParent()).bind(false, null);
Servlet s = allocate();
deallocate(s);
} catch (Throwable t) {
ExceptionUtils.handleThrowable(t);
} finally {
((Context) getParent()).unbind(false, oldCL);
}
return singleThreadModel;

} }




Expand Down
2 changes: 1 addition & 1 deletion java/org/apache/catalina/core/mbeans-descriptors.xml
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -1609,7 +1609,7 @@


<attribute name="singleThreadModel" <attribute name="singleThreadModel"
description="Does this servlet implement the SingleThreadModel interface?" description="Does this servlet implement the SingleThreadModel interface?"
type="boolean" type="java.lang.Boolean"
is="true" is="true"
writeable="false" /> writeable="false" />


Expand Down
7 changes: 7 additions & 0 deletions webapps/docs/changelog.xml
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -51,6 +51,13 @@
<bug>59813</bug>: Ensure that circular relations of the Class-Path <bug>59813</bug>: Ensure that circular relations of the Class-Path
attribute from JAR manifests will be processed correctly. (violetagg) attribute from JAR manifests will be processed correctly. (violetagg)
</fix> </fix>
<fix>
Ensure that reading the <code>singleThreadModel</code> attribute of a
<code>StandardWrapper</code> via JMX does not trigger initialisation of
the associated servlet. With some frameworks this can trigger an
unexpected initialisation thread and if initilisation is not thread-safe
the initialisation can then fail. (markt)
</fix>
</changelog> </changelog>
</subsection> </subsection>
<subsection name="Jasper"> <subsection name="Jasper">
Expand Down

0 comments on commit cec6459

Please sign in to comment.