Professional Documents
Culture Documents
Classloader leaks
Mattias Jiderhamn
java.lang.OutOfMemoryError:
Metaspace
PermGen space
.war
Heap
Heap
Young generation
Eden Survivor Old generation /
space space tenured space
Foo
GC roots
Mattias Jiderhamn – java.jiderhamn.se
Redeploy
Application Server
Instance
ClassLoader
Instance
GC root
ClassLoader
com.mysql.jdbc.Driver
app.war
mysql-jdbc.jar
… or 2)
DriverManager.deregisterDriver(…)
Mattias Jiderhamn – java.jiderhamn.se
Context shutdown
public class MyCleanupListener implements
javax.servlet.ServletContextListener {
...
...
public void run() {
while(true) { // Bad idea!
// Do something
}
}
}
Mattias Jiderhamn – java.jiderhamn.se
Stopping threads
public class MyThread extends Thread
{
private volatile boolean running = true;
private boolean running = true;
public void run() {
while(running) { // Until stopped
// Do something
}
}
public void shutdown() {
running = false;
} Kabutz / Java Specialists’ - The Law of the Blind Spot
Heinz
} Mattias Jiderhamn – java.jiderhamn.se
Threads
• Thread stack
– Local variables
– Method parameters
• MyThread extends Thread
MyRunnable implements Runnable
• contextClassLoader +
AccessControlContext inherited
– Example HTTP 1.1 Keep-Alive-Timer
• ThreadLocal
Mattias Jiderhamn – java.jiderhamn.se
ThreadLocal
ThreadLocal
WeakHashMap<Thread, ?>
Thread Foo
put() ThreadLocalMap
Entry
ThreadLocal Foo
set()
Mattias Jiderhamn – java.jiderhamn.se
ThreadLocal (?)
Pooled threads:
• Threads may outlive ClassLoader
• ThreadLocal → ThreadGlobal!
ThreadLocalMap
Entry
ThreadLocal Foo
static
ThreadLocalMap
Entry
Stale entry
ThreadLocal Foo
ClassLoader Class
Removed in 6.0.27
Bugzilla #48895
ThreadLocal Foo
Application Server
validation-api-1.0.0.GA.jar
app.war
hibernate-validator.jar
CXF-5442
-XX:+HeapDumpOnOutOfMemoryError
-XX:HeapDumpPath=/temp
???
Join the fight!
Mattias Jiderhamn – java.jiderhamn.se