Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » Perm Gen Error with EMF Classes on Tomcat(Perm Gen Error with EMF Classes on Tomcat)
Perm Gen Error with EMF Classes on Tomcat [message #992259] Fri, 21 December 2012 08:23 Go to next message
Appasamy Thirugnana is currently offline Appasamy ThirugnanaFriend
Messages: 27
Registered: September 2012
Junior Member
Hi All,

I am getting below errors when I do hot deployment of my WAR file in Tomcat 6.0.36 in Linux machine.

The error is as below:

SEVERE: The web application [\sampleApp] created a ThreadLocal with key of type [org.eclipse.emf.ecore.impl.EClassImpl$1] (value [org.eclipse.emf.ecore.impl.EClassImpl$1@1ed9228]) 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.

Dec 21, 2012 11:33:47 AM org.apache.catalina.loader.WebappClassLoader checkThreadLocalMapForLeaks

SEVERE: The web application [\sampleApp] created a ThreadLocal with key of type [org.eclipse.emf.ecore.xml.type.util.XMLTypeUtil.CharArrayThreadLocal] (value [org.eclipse.emf.ecore.xml.type.util.XMLTypeUtil$CharArrayThreadLocal@166c9d1]) and a value of type [char[]] (value [[C@14bc24a]) but failed to remove it when the web application was stopped. This is very likely to create a memory leak.


Dec 21, 2012 11:33:47 AM org.apache.catalina.loader.WebappClassLoader checkThreadLocalMapForLeaks

SEVERE: The web application [\sampleApp] created a ThreadLocal with key of type [com.sun.xml.bind.v2.ClassFactory$1] (value [com.sun.xml.bind.v2.ClassFactory$1@c0a9c3]) and a value of type [java.util.WeakHashMap] (value [{class javax.xml.bind.annotation.W3CDomHandler=java.lang.ref.WeakReference@c96cad}]) but failed to remove it when the web application was stopped. This is very likely to create a memory leak.

Dec 21, 2012 11:33:47 AM org.apache.catalina.loader.WebappClassLoader checkThreadLocalMapForLeaks
SEVERE: The web application [\sampleApp] created a ThreadLocal with key of type [org.eclipse.emf.ecore.impl.EClassImpl$1] (value [org.eclipse.emf.ecore.impl.EClassImpl$1@1ed9228]) 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.


Dec 21, 2012 11:33:47 AM org.apache.catalina.loader.WebappClassLoader checkThreadLocalMapForLeaks
SEVERE: The web application [\sampleApp] created a ThreadLocal with key of type [org.eclipse.emf.ecore.xml.type.util.XMLTypeUtil.CharArrayThreadLocal] (value [org.eclipse.emf.ecore.xml.type.util.XMLTypeUtil$CharArrayThreadLocal@166c9d1]) and a value of type [char[]] (value [[C@1fdecee]) but failed to remove it when the web application was stopped. This is very likely to create a memory leak.



This is leading to Perm Gen error when I redeployment happens.

Please let me know if any solution exists.


EMF version I use is 2.8.0.v20120606-0717.


Thanks.

Appasamy





Re: Perm Gen Error with EMF Classes on Tomcat [message #992712 is a reply to message #992259] Sat, 22 December 2012 11:19 Go to previous messageGo to next message
Chad E is currently offline Chad EFriend
Messages: 2
Registered: December 2012
Junior Member
My goodness. I just spent the past 4 days trying to fix a problem which was almost identical to yours. I found many different explanations online - from a bug in Tomcat to a problem with your web.xml. In the end, I solved it. I'll share my solution with you, but please don't misunderstand me - I am not implying that my solution will definitely correct your problem. I can only say it worked for me. By the way, over time this problem brought down Tomcat (after lots of context reloads...got a PermGen error).

I am still fairly new at web app development. There are so many brilliant people who understand this 1000 times more than I ever will. Therefore, if I don't explain something correctly or if I'm completely wrong about any assumption, my fault. I'll just try to do my best.

In a nutshell, there is a "bug" in Tomcat (google "wiki", "tomcat", "memoryleakprotection"), but this problem is correctable on your end. The number one problem is your ThreadLocal object, which is static, right? What I believe is happening is this (based on my understanding, right or wrong): Tomcat has a reference to this ThreadLocal and when you reload the context (hot deployment), a new ThreadLocal is created for your app (because the classloader reloads all classes), but Tomcat is still in possession of the original static ThreadLocal; although, you are no longer able to access it.

My solution was to do two things:

1) I overrode the ThreadLocal class and made my own. This was a very simple implementation as I kept it as basic a possible. Doing this allowed me explicit control over the state of my ThreadLocal. For example, because I overrode the TL.set(), the ThreadLocal never set its "initialValue" which I never used anyway.

2) I implemented a ServletContextListener, and in contextDestroyed(), I made my best attempt to clear any data in my ThreadLocal. This meant to first remove the object inside (TL.remove()) and set the TL to null. And, it's probably a good idea to null-out any other statics hanging around - I don't know though, that's just a guess.

I did those two things and presto chango - problem gone! But, the solution did not work if I only used 1 or 2. I had to use both.

Not sure if this will be helpful, but here's my very simple ThreadLocal override. By the way, I was so damn pissed-off when I was dealing with this problem, I named my ThreadLocal, FU_ThreadLocal, as some sort of sick way of striking back.
[size=4]public class FU_ThreadLocal< T extends Object > extends ThreadLocal< T > {

	private T val ; 
	
	public FU_Local( ) {

		super( ) ; 
	}
	
	@Override
	public T get( ) {
	
		return( val ) ; 
	}
	
	@Override
	public void set( T value ) {
		
		val = value ; 
	}
	
	@Override
	protected T initialValue( ) {

		return( null ) ; 
	}
	
	@Override
	public void remove( ) {

		val = null ; 
	}

} // end

Within contextDestroyed( ), I called deathToTheLocal():
[size=4]public static void deathToTheLocal( ) {

	logger.debug( "Attempting to murder the ThreadLocal" ) ;

	try {
			
		threadLocal.remove( ) ; 
		threadLocal = null ;
			
		logger.debug( "The Local died like the girly-man he was" ) ; 
			
	} catch ( Exception e ) {

		logger.error( "Oops, the girly-man gave us a problem: " + e ) ;
	}
}

While debugging, it helped me to log the memory usage of my app. This was vital as it gives you an indication of whether or not you solved the problem. Before the solution, I would watch my memory creep up after every context reload, eventually crashing Tomcat. After I implemented my fix, my memory remained stable after the 2nd context reload. Within contextInitialized() and contextDestroyed(), I log the memory usage by retreiving the following string:
[size=4]public static String getMemoryStatusString( ) { 
		
    	long maxJVMMemory = Runtime.getRuntime( ).maxMemory( ) ; 
    	long freeJVMMemory = Runtime.getRuntime( ).freeMemory( ) ; 
    	long totalJVMMemory = Runtime.getRuntime( ).totalMemory( ) ; 
    	
    	double maxMemory = maxJVMMemory / 1000000.0 ; 
    	double freeMemory = freeJVMMemory / 1000000.0 ; 
    	double totalMemory = totalJVMMemory / 1000000.0 ; 
    	
    	DecimalFormat df = new DecimalFormat("#.##");
    	String maxMem = df.format( maxMemory ) ; 
    	String freeMem = df.format( freeMemory ) ; 
    	String totalMem = df.format( totalMemory ) ;  
    	
    	String status = ( "	---MEMORY--- MAX:" + maxMem + "MB / FREE:" + freeMem + "MB / TOTAL:" + totalMem + "MB" ) ;
    	
    	return( status ) ;    
		  
	} // end[/size]


I'm not sure if any of this will help you, but I hope so (or at least I hope it helps someone else).
Re: Perm Gen Error with EMF Classes on Tomcat [message #992841 is a reply to message #992259] Sat, 22 December 2012 19:47 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 26289
Registered: July 2009
Senior Member
Appasamy,

I'm not sure how these things lead to permgen space problems. I would
have expected thread locals to be cleaned up when a thread is cleaned up...

On 21/12/2012 12:23 AM, Appasamy Thirugnana wrote:
> Hi All,
>
> I am getting below errors when I do hot deployment of my WAR file in
> Tomcat 6.0.36 in Linux machine.
>
> The error is as below:
>
> SEVERE: The web application [\sampleApp] created a ThreadLocal with
> key of type [org.eclipse.emf.ecore.impl.EClassImpl$1] (value
> [org.eclipse.emf.ecore.impl.EClassImpl$1@1ed9228]) 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.
>
> Dec 21, 2012 11:33:47 AM org.apache.catalina.loader.WebappClassLoader
> checkThreadLocalMapForLeaks
>
> SEVERE: The web application [\sampleApp] created a ThreadLocal with
> key of type
> [org.eclipse.emf.ecore.xml.type.util.XMLTypeUtil.CharArrayThreadLocal]
> (value
> [org.eclipse.emf.ecore.xml.type.util.XMLTypeUtil$CharArrayThreadLocal@166c9d1])
> and a value of type [char[]] (value [[C@14bc24a]) but failed to remove
> it when the web application was stopped. This is very likely to create
> a memory leak.
>
>
> Dec 21, 2012 11:33:47 AM org.apache.catalina.loader.WebappClassLoader
> checkThreadLocalMapForLeaks
>
> SEVERE: The web application [\sampleApp] created a ThreadLocal with
> key of type [com.sun.xml.bind.v2.ClassFactory$1] (value
> [com.sun.xml.bind.v2.ClassFactory$1@c0a9c3]) and a value of type
> [java.util.WeakHashMap] (value [{class
> javax.xml.bind.annotation.W3CDomHandler=java.lang.ref.WeakReference@c96cad}])
> but failed to remove it when the web application was stopped. This is
> very likely to create a memory leak.
>
> Dec 21, 2012 11:33:47 AM org.apache.catalina.loader.WebappClassLoader
> checkThreadLocalMapForLeaks
> SEVERE: The web application [\sampleApp] created a ThreadLocal with
> key of type [org.eclipse.emf.ecore.impl.EClassImpl$1] (value
> [org.eclipse.emf.ecore.impl.EClassImpl$1@1ed9228]) 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.
>
>
> Dec 21, 2012 11:33:47 AM org.apache.catalina.loader.WebappClassLoader
> checkThreadLocalMapForLeaks
> SEVERE: The web application [\sampleApp] created a ThreadLocal with
> key of type
> [org.eclipse.emf.ecore.xml.type.util.XMLTypeUtil.CharArrayThreadLocal]
> (value
> [org.eclipse.emf.ecore.xml.type.util.XMLTypeUtil$CharArrayThreadLocal@166c9d1])
> and a value of type [char[]] (value [[C@1fdecee]) but failed to remove
> it when the web application was stopped. This is very likely to create
> a memory leak.
>
>
> This is leading to Perm Gen error when I redeployment happens.
>
> Please let me know if any solution exists.
>
>
> EMF version I use is 2.8.0.v20120606-0717.
>
>
> Thanks.
>
> Appasamy
>
>
>
>
>
>
Re: Perm Gen Error with EMF Classes on Tomcat [message #992846 is a reply to message #992841] Sat, 22 December 2012 20:08 Go to previous messageGo to next message
Martin Taal is currently offline Martin TaalFriend
Messages: 5340
Registered: July 2009
Senior Member
Hi,
Tomcat will re-use threads, it has a thread pool and when it handles requests it will take a thread object from the pool
and put it back after the request has been done.

gr. Martin

On 12/22/2012 08:47 PM, Ed Merks wrote:
> Appasamy,
>
> I'm not sure how these things lead to permgen space problems. I would have expected thread locals to be cleaned up
> when a thread is cleaned up...
>
> On 21/12/2012 12:23 AM, Appasamy Thirugnana wrote:
>> Hi All,
>>
>> I am getting below errors when I do hot deployment of my WAR file in Tomcat 6.0.36 in Linux machine.
>>
>> The error is as below:
>>
>> SEVERE: The web application [\sampleApp] created a ThreadLocal with key of type
>> [org.eclipse.emf.ecore.impl.EClassImpl$1] (value [org.eclipse.emf.ecore.impl.EClassImpl$1@1ed9228]) 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.
>>
>> Dec 21, 2012 11:33:47 AM org.apache.catalina.loader.WebappClassLoader checkThreadLocalMapForLeaks
>>
>> SEVERE: The web application [\sampleApp] created a ThreadLocal with key of type
>> [org.eclipse.emf.ecore.xml.type.util.XMLTypeUtil.CharArrayThreadLocal] (value
>> [org.eclipse.emf.ecore.xml.type.util.XMLTypeUtil$CharArrayThreadLocal@166c9d1]) and a value of type [char[]] (value
>> [[C@14bc24a]) but failed to remove it when the web application was stopped. This is very likely to create a memory leak.
>>
>>
>> Dec 21, 2012 11:33:47 AM org.apache.catalina.loader.WebappClassLoader checkThreadLocalMapForLeaks
>>
>> SEVERE: The web application [\sampleApp] created a ThreadLocal with key of type [com.sun.xml.bind.v2.ClassFactory$1]
>> (value [com.sun.xml.bind.v2.ClassFactory$1@c0a9c3]) and a value of type [java.util.WeakHashMap] (value [{class
>> javax.xml.bind.annotation.W3CDomHandler=java.lang.ref.WeakReference@c96cad}]) but failed to remove it when the web
>> application was stopped. This is very likely to create a memory leak.
>>
>> Dec 21, 2012 11:33:47 AM org.apache.catalina.loader.WebappClassLoader checkThreadLocalMapForLeaks
>> SEVERE: The web application [\sampleApp] created a ThreadLocal with key of type
>> [org.eclipse.emf.ecore.impl.EClassImpl$1] (value [org.eclipse.emf.ecore.impl.EClassImpl$1@1ed9228]) 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.
>>
>>
>> Dec 21, 2012 11:33:47 AM org.apache.catalina.loader.WebappClassLoader checkThreadLocalMapForLeaks
>> SEVERE: The web application [\sampleApp] created a ThreadLocal with key of type
>> [org.eclipse.emf.ecore.xml.type.util.XMLTypeUtil.CharArrayThreadLocal] (value
>> [org.eclipse.emf.ecore.xml.type.util.XMLTypeUtil$CharArrayThreadLocal@166c9d1]) and a value of type [char[]] (value
>> [[C@1fdecee]) but failed to remove it when the web application was stopped. This is very likely to create a memory leak.
>>
>>
>> This is leading to Perm Gen error when I redeployment happens.
>>
>> Please let me know if any solution exists.
>>
>>
>> EMF version I use is 2.8.0.v20120606-0717.
>>
>>
>> Thanks.
>>
>> Appasamy
>>
>>
>>
>>
>>
>>
>


--

With Regards, Martin Taal

Springsite/Elver.org
Office: Hardwareweg 4, 3821 BV Amersfoort
Postal: Nassaulaan 7, 3941 EC Doorn
The Netherlands
Cell: +31 (0)6 288 48 943
Tel: +31 (0)84 420 2397
Fax: +31 (0)84 225 9307
Mail: mtaal@xxxxxxxx - mtaal@xxxxxxxx
Web: www.springsite.com - www.elver.org
Re: Perm Gen Error with EMF Classes on Tomcat [message #993420 is a reply to message #992846] Mon, 24 December 2012 10:24 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 26289
Registered: July 2009
Senior Member
<html>
<head>
<meta content="text/html; charset=UTF-8" http-equiv="Content-Type">
</head>
<body text="#000000" bgcolor="#FFFFFF">
Martin,<br>
<br>
Looking at the specifics of his trace the two places the core
runtime uses ThreadLocal are<br>
<blockquote>org.eclipse.emf.ecore.impl.EClassImpl.COMPUTATION_IN_PROGRESS<br>
org.eclipse.emf.ecore.xml.type.util.XMLTypeUtil.VALUE<br>
</blockquote>
In the first case, it's used to cache a HashSet that's used to
prevent infinite recursion when there is circular inheritance; the
set should always be empty except during a EClass.getAll* call. In
the second case, it caches a character array. So in either case, the
leak will be a character array or an empty HasSet.  I don't see that
either represents a large memory leak and I don't see how either can
case a PermGen problem; I suppose it has something to do with the
java.lang.Thread.threadLocals cache itself holding on to the
instance that holds onto the class loader that holds onto all the
classes, but I don't see how I can clean that out.  I see there is a
new method for 1.5 java.lang.ThreadLocal.remove() that might work in
conjunction with javax.servlet.ServletContextListener but I dislike
the idea of adding a dependency to such an API...<br>
<br>
<br>
<div class="moz-cite-prefix">On 22/12/2012 9:08 PM, Martin Taal
wrote:<br>
</div>
<blockquote cite="mid:kb540c$gnp$1@xxxxxxxxe.org" type="cite">Hi,
<br>
Tomcat will re-use threads, it has a thread pool and when it
handles requests it will take a thread object from the pool and
put it back after the request has been done.
<br>
<br>
gr. Martin
<br>
<br>
On 12/22/2012 08:47 PM, Ed Merks wrote:
<br>
<blockquote type="cite">Appasamy,
<br>
<br>
I'm not sure how these things lead to permgen space problems.  
I would have expected thread locals to be cleaned up
<br>
when a thread is cleaned up...
<br>
<br>
On 21/12/2012 12:23 AM, Appasamy Thirugnana wrote:
<br>
<blockquote type="cite">Hi All,
<br>
<br>
I am getting below errors when I do hot deployment of my WAR
file in Tomcat 6.0.36 in Linux machine.
<br>
<br>
The error is as below:
<br>
<br>
SEVERE: The web application [\sampleApp] created a ThreadLocal
with key of type
<br>
[org.eclipse.emf.ecore.impl.EClassImpl$1] (value
[org.eclipse.emf.ecore.impl.EClassImpl$1@1ed9228]) and a value
of
<br>
type [java.util.HashSet] (value [[]]) but failed to remove it
when the web application was stopped. This is very
<br>
likely to create a memory leak.
<br>
<br>
Dec 21, 2012 11:33:47 AM
org.apache.catalina.loader.WebappClassLoader
checkThreadLocalMapForLeaks
<br>
<br>
SEVERE: The web application [\sampleApp] created a ThreadLocal
with key of type
<br>
[org.eclipse.emf.ecore.xml.type.util.XMLTypeUtil.CharArrayThreadLocal]
(value
<br>
[org.eclipse.emf.ecore.xml.type.util.XMLTypeUtil$CharArrayThreadLocal@166c9d1])
and a value of type [char[]] (value
<br>
[[C@14bc24a]) but failed to remove it when the web application
was stopped. This is very likely to create a memory leak.
<br>
<br>
<br>
Dec 21, 2012 11:33:47 AM
org.apache.catalina.loader.WebappClassLoader
checkThreadLocalMapForLeaks
<br>
<br>
SEVERE: The web application [\sampleApp] created a ThreadLocal
with key of type [com.sun.xml.bind.v2.ClassFactory$1]
<br>
(value [com.sun.xml.bind.v2.ClassFactory$1@c0a9c3]) and a
value of type [java.util.WeakHashMap] (value [{class
<br>
javax.xml.bind.annotation.W3CDomHandler=java.lang.ref.WeakReference@c96cad}])
but failed to remove it when the web
<br>
application was stopped. This is very likely to create a
memory leak.
<br>
<br>
Dec 21, 2012 11:33:47 AM
org.apache.catalina.loader.WebappClassLoader
checkThreadLocalMapForLeaks
<br>
SEVERE: The web application [\sampleApp] created a ThreadLocal
with key of type
<br>
[org.eclipse.emf.ecore.impl.EClassImpl$1] (value
[org.eclipse.emf.ecore.impl.EClassImpl$1@1ed9228]) and a value
of
<br>
type [java.util.HashSet] (value [[]]) but failed to remove it
when the web application was stopped. This is very
<br>
likely to create a memory leak.
<br>
<br>
<br>
Dec 21, 2012 11:33:47 AM
org.apache.catalina.loader.WebappClassLoader
checkThreadLocalMapForLeaks
<br>
SEVERE: The web application [\sampleApp] created a ThreadLocal
with key of type
<br>
[org.eclipse.emf.ecore.xml.type.util.XMLTypeUtil.CharArrayThreadLocal]
(value
<br>
[org.eclipse.emf.ecore.xml.type.util.XMLTypeUtil$CharArrayThreadLocal@166c9d1])
and a value of type [char[]] (value
<br>
[[C@1fdecee]) but failed to remove it when the web application
was stopped. This is very likely to create a memory leak.
<br>
<br>
<br>
This is leading to Perm Gen error when I redeployment happens.
<br>
<br>
Please let me know if any solution exists.
<br>
<br>
<br>
EMF version I use is 2.8.0.v20120606-0717.
<br>
<br>
<br>
Thanks.
<br>
<br>
Appasamy
<br>
<br>
<br>
<br>
<br>
<br>
<br>
</blockquote>
<br>
</blockquote>
<br>
<br>
</blockquote>
<br>
</body>
</html>
Re: Perm Gen Error with EMF Classes on Tomcat [message #993467 is a reply to message #993420] Mon, 24 December 2012 13:37 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 26289
Registered: July 2009
Senior Member
<html>
<head>
<meta content="text/html; charset=UTF-8" http-equiv="Content-Type">
</head>
<body text="#000000" bgcolor="#FFFFFF">
Investigating a bit more, I think I could provide something like
this in EcorePlugin<br>
<br>
  /**<br>
   * The set of thread locals that can be {@link
ThreadLocal#remove() cleaned up manually} when a thread is recycled
for reuse in a {@link javax.servlet.ServletContextListener servlet
context}.<br>
   * @since 2.9<br>
   */<br>
  public static Set&lt;ThreadLocal&lt;?&gt;&gt; THREAD_LOCALS =
Collections.synchronizedSet(new
HashSet&lt;ThreadLocal&lt;?&gt;&gt;());<br>
<br>
and add to that the two thread locals used by the runtime.   I.e.,<br>
<br>
    public CharArrayThreadLocal()<br>
    {<br>
      EcorePlugin.THREAD_LOCALS.add(this);<br>
    }<br>
<br>
and<br>
<br>
  private static final ThreadLocal&lt;Set&lt;EClass&gt;&gt;
COMPUTATION_IN_PROGRESS = <br>
    new ThreadLocal&lt;Set&lt;EClass&gt;&gt;()<br>
    {<br>
      {<br>
        EcorePlugin.THREAD_LOCALS.add(this);<br>
      }<br>
<br>
A client could then register a servlet context listener and iterate
over this set to call remove on each one.<br>
<br>
I wonder if that would do the trick?  If so, please open a
bugzilla.  <br>
<br>
Thanks Chad for your very useful post!<br>
<br>
<br>
<div class="moz-cite-prefix">On 24/12/2012 11:24 AM, Ed Merks wrote:<br>
</div>
<blockquote cite="mid:kb9ah3$729$1@xxxxxxxxe.org" type="cite">
<meta content="text/html; charset=UTF-8" http-equiv="Content-Type">
Martin,<br>
<br>
Looking at the specifics of his trace the two places the core
runtime uses ThreadLocal are<br>
<blockquote>org.eclipse.emf.ecore.impl.EClassImpl.COMPUTATION_IN_PROGRESS<br>
org.eclipse.emf.ecore.xml.type.util.XMLTypeUtil.VALUE<br>
</blockquote>
In the first case, it's used to cache a HashSet that's used to
prevent infinite recursion when there is circular inheritance; the
set should always be empty except during a EClass.getAll* call. In
the second case, it caches a character array. So in either case,
the leak will be a character array or an empty HasSet.  I don't
see that either represents a large memory leak and I don't see how
either can case a PermGen problem; I suppose it has something to
do with the java.lang.Thread.threadLocals cache itself holding on
to the instance that holds onto the class loader that holds onto
all the classes, but I don't see how I can clean that out.  I see
there is a new method for 1.5 java.lang.ThreadLocal.remove() that
might work in conjunction with
javax.servlet.ServletContextListener but I dislike the idea of
adding a dependency to such an API...<br>
<br>
<br>
<div class="moz-cite-prefix">On 22/12/2012 9:08 PM, Martin Taal
wrote:<br>
</div>
<blockquote cite="mid:kb540c$gnp$1@xxxxxxxxe.org" type="cite">Hi,

<br>
Tomcat will re-use threads, it has a thread pool and when it
handles requests it will take a thread object from the pool and
put it back after the request has been done. <br>
<br>
gr. Martin <br>
<br>
On 12/22/2012 08:47 PM, Ed Merks wrote: <br>
<blockquote type="cite">Appasamy, <br>
<br>
I'm not sure how these things lead to permgen space
problems.   I would have expected thread locals to be cleaned
up <br>
when a thread is cleaned up... <br>
<br>
On 21/12/2012 12:23 AM, Appasamy Thirugnana wrote: <br>
<blockquote type="cite">Hi All, <br>
<br>
I am getting below errors when I do hot deployment of my WAR
file in Tomcat 6.0.36 in Linux machine. <br>
<br>
The error is as below: <br>
<br>
SEVERE: The web application [\sampleApp] created a
ThreadLocal with key of type <br>
[org.eclipse.emf.ecore.impl.EClassImpl$1] (value
[org.eclipse.emf.ecore.impl.EClassImpl$1@1ed9228]) and a
value of <br>
type [java.util.HashSet] (value [[]]) but failed to remove
it when the web application was stopped. This is very <br>
likely to create a memory leak. <br>
<br>
Dec 21, 2012 11:33:47 AM
org.apache.catalina.loader.WebappClassLoader
checkThreadLocalMapForLeaks <br>
<br>
SEVERE: The web application [\sampleApp] created a
ThreadLocal with key of type <br>
[org.eclipse.emf.ecore.xml.type.util.XMLTypeUtil.CharArrayThreadLocal]

(value <br>
[org.eclipse.emf.ecore.xml.type.util.XMLTypeUtil$CharArrayThreadLocal@166c9d1])

and a value of type [char[]] (value <br>
[[C@14bc24a]) but failed to remove it when the web
application was stopped. This is very likely to create a
memory leak. <br>
<br>
<br>
Dec 21, 2012 11:33:47 AM
org.apache.catalina.loader.WebappClassLoader
checkThreadLocalMapForLeaks <br>
<br>
SEVERE: The web application [\sampleApp] created a
ThreadLocal with key of type
[com.sun.xml.bind.v2.ClassFactory$1] <br>
(value [com.sun.xml.bind.v2.ClassFactory$1@c0a9c3]) and a
value of type [java.util.WeakHashMap] (value [{class <br>
javax.xml.bind.annotation.W3CDomHandler=java.lang.ref.WeakReference@c96cad}])

but failed to remove it when the web <br>
application was stopped. This is very likely to create a
memory leak. <br>
<br>
Dec 21, 2012 11:33:47 AM
org.apache.catalina.loader.WebappClassLoader
checkThreadLocalMapForLeaks <br>
SEVERE: The web application [\sampleApp] created a
ThreadLocal with key of type <br>
[org.eclipse.emf.ecore.impl.EClassImpl$1] (value
[org.eclipse.emf.ecore.impl.EClassImpl$1@1ed9228]) and a
value of <br>
type [java.util.HashSet] (value [[]]) but failed to remove
it when the web application was stopped. This is very <br>
likely to create a memory leak. <br>
<br>
<br>
Dec 21, 2012 11:33:47 AM
org.apache.catalina.loader.WebappClassLoader
checkThreadLocalMapForLeaks <br>
SEVERE: The web application [\sampleApp] created a
ThreadLocal with key of type <br>
[org.eclipse.emf.ecore.xml.type.util.XMLTypeUtil.CharArrayThreadLocal]

(value <br>
[org.eclipse.emf.ecore.xml.type.util.XMLTypeUtil$CharArrayThreadLocal@166c9d1])

and a value of type [char[]] (value <br>
[[C@1fdecee]) but failed to remove it when the web
application was stopped. This is very likely to create a
memory leak. <br>
<br>
<br>
This is leading to Perm Gen error when I redeployment
happens. <br>
<br>
Please let me know if any solution exists. <br>
<br>
<br>
EMF version I use is 2.8.0.v20120606-0717. <br>
<br>
<br>
Thanks. <br>
<br>
Appasamy <br>
<br>
<br>
<br>
<br>
<br>
<br>
</blockquote>
<br>
</blockquote>
<br>
<br>
</blockquote>
<br>
</blockquote>
<br>
</body>
</html>
Re: Perm Gen Error with EMF Classes on Tomcat [message #993783 is a reply to message #993467] Tue, 25 December 2012 13:18 Go to previous messageGo to next message
Chad E is currently offline Chad EFriend
Messages: 2
Registered: December 2012
Junior Member
You're welcome Ed. I'm just glad someone found it useful!
Re: Perm Gen Error with EMF Classes on Tomcat [message #994011 is a reply to message #993783] Wed, 26 December 2012 05:50 Go to previous messageGo to next message
Appasamy Thirugnana is currently offline Appasamy ThirugnanaFriend
Messages: 27
Registered: September 2012
Junior Member
Hi Ed and Chad,

Thanks for the informative reply. I will try out this today and let you know the output. I was on vacation so did not reply immediately.

Hi Chad,

Below question may not be applicable to EMF but would like to know how I remove threadlocal in my context listener in spring and I have below implementation to get hold when context reloads.
I created custom Threadlocal as provided.



import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;

import org.springframework.context.annotation.Configuration;

@Configuration
public class CustomContextListener
{

   @PostConstruct
   public void contextInitialized()
   {
     System.out.println("Context Initialised");
   }

   @PreDestroy
   public void contextdestroyed()
   {
      System.out.println("Context Destroyed");
   }

}



or traditional way like below also I can do but I am not aware how to access threadlocal in that.

public class CustomServletContextListener implements ServletContextListener{
	ServletContext context;
	public void contextInitialized(ServletContextEvent contextEvent) {
		System.out.println("Context Created");
		context = contextEvent.getServletContext();
	}
	public void contextDestroyed(ServletContextEvent contextEvent) {
		System.out.println("Context Destroyed");
	}
}




Thanks,
Appasamy






















Re: Perm Gen Error with EMF Classes on Tomcat [message #994069 is a reply to message #994011] Wed, 26 December 2012 09:54 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 26289
Registered: July 2009
Senior Member
Appasamy,

I don't think there is a general way to access the thread locals (except
perhaps via reflection, which involves access to package protected
things, i.e., java.lang.Thread.threadLocals, so not something you can
do with a security manager in place). An alternative to what I proposed
for EMF (which is essentially giving you direct access to EMF's thread
locals so you can clean them up in your contextDestoryed method) would
be not to subclass the thread local so that there would only be a very
small leak (the thread local instance itself along with its character
array and empty HashSet) rather than leaking everything loaded by the
class loader, i.e., the whole EMF runtime library.


On 26/12/2012 6:50 AM, Appasamy Thirugnana wrote:
> Hi Ed and Chad,
>
> Thanks for the informative reply. I will try out this today and let
> you know the output. I was on vacation so did not reply immediately.
>
> Hi Chad,
>
> Below question may not be applicable to EMF but would like to know how
> I remove threadlocal in my context listener in spring and I have below
> implementation to get hold when context reloads.
> I created custom Threadlocal as provided.
>
>
>
> import javax.annotation.PostConstruct;
> import javax.annotation.PreDestroy;
>
> import org.springframework.context.annotation.Configuration;
>
> @Configuration
> public class CustomContextListener
> {
>
> @PostConstruct
> public void contextInitialized()
> {
> System.out.println("Context Initialised");
> }
>
> @PreDestroy
> public void contextdestroyed()
> {
> System.out.println("Context Destroyed");
> }
>
> }
>
>
>
> or traditional way like below also I can do but I am not aware how to
> access threadlocal in that.
>
> public class CustomServletContextListener implements
> ServletContextListener{
> ServletContext context;
> public void contextInitialized(ServletContextEvent contextEvent) {
> System.out.println("Context Created");
> context = contextEvent.getServletContext();
> }
> public void contextDestroyed(ServletContextEvent contextEvent) {
> System.out.println("Context Destroyed");
> }
> }
>
>
>
>
> Thanks,
> Appasamy
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
Re: Perm Gen Error with EMF Classes on Tomcat [message #994080 is a reply to message #994069] Wed, 26 December 2012 10:30 Go to previous messageGo to next message
Appasamy Thirugnana is currently offline Appasamy ThirugnanaFriend
Messages: 27
Registered: September 2012
Junior Member
Hi Ed,

Thanks for the reply and now I understand.
I will wait for the next release to use this and cleanup in my contextDestoryed method.

Thanks,
Appasamy
Re: Perm Gen Error with EMF Classes on Tomcat [message #994236 is a reply to message #994080] Wed, 26 December 2012 19:57 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 26289
Registered: July 2009
Senior Member
Appasamy,

Please open a bugzilla and try out a build when the feature is available
to confirm it works properly.


On 26/12/2012 11:30 AM, Appasamy Thirugnana wrote:
> Hi Ed,
>
> Thanks for the reply and now I understand.
> I will wait for the next release to use this and cleanup in my
> contextDestoryed method.
>
> Thanks,
> Appasamy
Re: Perm Gen Error with EMF Classes on Tomcat [message #996838 is a reply to message #992259] Thu, 03 January 2013 02:05 Go to previous message
Appasamy Thirugnana is currently offline Appasamy ThirugnanaFriend
Messages: 27
Registered: September 2012
Junior Member
Hi Ed Merks,

I created a bug as suggested

https://bugs.eclipse.org/bugs/show_bug.cgi?id=397171


Thanks.

Appasamy

Previous Topic:[CDO] StringIndexOutOfBoundsException thrown for a column containing a single space using H2
Next Topic:EMF RCP from e3 to e4
Goto Forum:
  


Current Time: Mon Dec 22 16:24:51 GMT 2014

Powered by FUDForum. Page generated in 0.02881 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software