3

EDIT: The solution that you can find in comments below assumes changing JSF implemenetation from MyFaces to Sun's Mojarra.

Hi,

I have got really annoying problem with MyFaces 2.0.0 (To be more precisely I checked it out also on 2.0.1 and 2.0.2 and problem remains).

I'm writing now application under MyFaces. Briefly speaking in my application i use frameworks: Spring, Hibernate, JSF (MyFaces implementation) My application container is Tomcat (6.0.29 version) I use maven to build and deploy (version 3.0).

The problem is when I try to redeploy application via maven (mvn tomcat:redeploy) it tries first to undeploy application and the deploy it again. But undeploying never suceed. I've got information:

SEVERE: The web application [/adam] created a ThreadLocal with key of type 
[java.lang.ThreadLocal] (value [java.lang.ThreadLocal@4b0a4d7c]) and a value of type
[org.apache.myfaces.config.RuntimeConfig] (value  org.apache.myfaces.config.RuntimeConfig@11652e61])
but failed to remove it when the web application was stopped.
This is very likely to create a memory leak.

Due to this error tomcat cannot undeploy application:

INFO: Undeploying context [/adam]
2010-12-02 11:47:46 org.apache.catalina.startup.ExpandWar deleteDir
SEVERE: [D:\Program Files\apache-tomcat-6.0.29\webapps\adam\WEB-INF\lib] could not be completely deleted. The presence of the remaining files may cause problems
2010-12-02 11:47:46 org.apache.catalina.startup.ExpandWar deleteDir
SEVERE: [D:\Program Files\apache-tomcat-6.0.29\webapps\adam\WEB-INF] could not be completely deleted. The presence of the remaining files may cause problems
2010-12-02 11:47:46 org.apache.catalina.startup.ExpandWar deleteDir
SEVERE: [D:\Program Files\apache-tomcat-6.0.29\webapps\adam] could not be completely deleted. The presence of the remaining files may cause problems
2010-12-02 11:47:46 org.apache.catalina.startup.ExpandWar delete
SEVERE: [D:\Program Files\apache-tomcat-6.0.29\webapps\adam] could not be completely deleted. The presence of the remaining files may cause problems
2010-12-02 11:47:49 org.apache.catalina.startup.HostConfig deployDirectory

All of my libraries in WEB-INF\lib and my file where i keep logs from Log4J cannot be deleted.

There is also connected memory leak from library that provides ELFactoryImpl:

SEVERE: The web application [/adam] created a ThreadLocal with key of type [null]
(value [org.apache.myfaces.el.convert.VariableResolverToELResolver$1@693985fc])
and a value of type [java.util.HashSet] (value [[]]) but failed to remove it
when the web application was stopped.
This is very likely to create a memory leak.

How to get rid of this memory leaks ?

I have been looking for answer really long I cannot find any solution. I found this issue on myface's jira: https://issues.apache.org/jira/browse/MYFACES-2942 But I don't know what to think about it. Should I wait for version 2.0.3 ?

I think that memory leak from EL is connected to first one.

Please, help me ! ;) I can provide more details if needed.

Carter Allen
  • 1,984
  • 15
  • 22
Kamil Sobon
  • 45
  • 2
  • 7

1 Answers1

2

The problem has already been reported and will be fixed. As of now you have 3 options:

  1. Live with the warning message and wait until MyFaces guys release the fix.

  2. Apply the proposed patch in your current MyFaces implementation.

  3. Replace MyFaces by Mojarra (the reference implementation) which doesn't expose this problem.

Community
  • 1
  • 1
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
  • "Apply the proposed patch in your current MyFaces implementation.". My question will be really stupid now ;) How to do this ? AFAIK i should use patch UNIX tool. Am I right ? But how to do this under Windows system ? By using Cygwin ? – Kamil Sobon Dec 02 '10 at 11:48
  • They uses SVN. If you don't have SVN, you have to downoad a nightly build or to apply it manually on the MyFaces source and recompile/repackage the JAR. However, I can't seem to find a nightly build on the forest at http://myfaces.apache.org. The download folders are empty. Anyway, is there any reason that you prefer MyFaces over the superior Mojarra? – BalusC Dec 02 '10 at 12:23
  • "Anyway, is there any reason that you prefer MyFaces over the superior Mojarra?" Only one reason: changes in documentation of my BSc Thesis and few changes in web.xml configuration. But that is not a big deal. I will try Mojarra. I hope that will help. If it will help, should I write about it in the comment ? (I am new here ;)) – Kamil Sobon Dec 02 '10 at 12:32
  • I've used Mojarra on Tomcat for years and I haven't ever seen those memory leaks. You can just comment here if it helped. – BalusC Dec 02 '10 at 12:41
  • It didn't helped: "SEVERE: The web application [/adam] created a ThreadLocal with key of type [null] (value [com.sun.faces.util.Util$1@4d885088]) and a value of type [java.util.HashMap] (value [{com.sun.faces.patternCache={ = }}]) but failed to remove it when the web application was stopped. This is very likely to create a memory leak." Later i will check with MAT what is it. Any clue ? – Kamil Sobon Dec 02 '10 at 14:12
  • Hmm, I will check this later the day. – BalusC Dec 02 '10 at 14:14
  • This has been introduced in the new 2.0.3 (while it works fine for 2.0.2 and before). The issue has been reported as well and is fixed for 2.1: https://javaserverfaces.dev.java.net/issues/show_bug.cgi?id=1730 In the meanwhile, you might want to pick [2.0.2](https://javaserverfaces.dev.java.net/servlets/ProjectDocumentList?folderID=11965&expandFolder=11965&folderID=5220) instead. – BalusC Dec 02 '10 at 14:57
  • Success ! There are no memory leaks so far. But still while undeploying application tomcat is unable to remove jars from WEB-INF/lib. Sometimes all of them, sometimes jsf-impl-2.0.2.jar only. I have no clue why this happens. I will try to investigate this issue. And i have to check if mojarra doesn't changes my application behavior. Have you ever had this type of situation when tomcat could not undeploy application ? – Kamil Sobon Dec 02 '10 at 17:07
  • You need to add `antiResourceLocking="true"` to the `` element in `/META-INF/context.xml`. – BalusC Dec 02 '10 at 17:09
  • Brilliant ! Thanks a lot ! Now I have to check if my ajax requests works fine under mojarra. But both of my problems have been solved. I own you a beer! But it can take a lot to send it to You from Poland ;) I have got a question, how do You know so much about JSF ? Years of experience or there is really got blog about JSF that I have missed ? – Kamil Sobon Dec 02 '10 at 17:22
  • You're welcome. It's a combination of years of experience and a pretty strong memory. I actually own a JSF blog at http://balusc.blogspot.com. It's however mainly targeted on JSF 1.2. – BalusC Dec 02 '10 at 17:29
  • I have change JSF 1.2 to 2.0 due to the fact that JSF 1.2 swallowed sometimes exceptions which were thrown by code. I have werid situation with primefaces. There is no notification in one of my page. This also happens under MyFaces 2.0.2 – Kamil Sobon Dec 02 '10 at 17:36
  • When using `actionListener` in JSF 1.2, it will indeed swallow exceptions. You should use `action` instead. In PrimeFaces with Ajax, you should use `p:ajaxStatus` for this. See also my answer on [this related question](http://stackoverflow.com/questions/4146524/javaee6-how-to-safeguard-web-application-when-the-database-shut-down). – BalusC Dec 02 '10 at 17:42
  • <- This (h:inputText + p:ajax) does not work under MyFaces 2.0.2 or Mojarra 2.0.2. Do you know why ? – Kamil Sobon Dec 02 '10 at 19:46
  • Is it inside a `h:form`? Does the condition of the `rendered` attribute evaluate the same during ajax request? (i.e. it's retained in next request; put bean in view scope to be sure). If you stucks, please ask a new question. Do not abuse comments for this :) – BalusC Dec 02 '10 at 19:54