1

My Java program crashes on mac due to OutOfMemoryError. When I tried to print all active threads, I found the below stacktrace. There were many instances of these threads which related to "sun.misc.Unsafe.park". One of the possible reasons can be presence of deadlock. Is there a way to find out which part of my program is responsible for this?

Thread Class: class java.lang.Thread|||
Thread id: 90|||||||
StackTrace:  sun.misc.Unsafe.park(Native Method)
java.util.concurrent.locks.LockSupport.park(LockSupport.java:175)
java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.await(AbstractQueuedSynchronizer.java:2039)
java.util.concurrent.LinkedBlockingQueue.take(LinkedBlockingQueue.java:442)
java.util.concurrent.ThreadPoolExecutor.getTask(ThreadPoolExecutor.java:1067)
java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1127)
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
java.lang.Thread.run(Thread.java:745) 
user207421
  • 305,947
  • 44
  • 307
  • 483
  • 1
    A deadlock wouldn't directly cause an OutOfMemoryError. Why don't you share some code? – shmosel Feb 23 '16 at 05:40
  • 2
    According to the stack trace these are just worker threads from a ThreadPoolExecutor and won't consume that much memory. However the problem could be http://stackoverflow.com/questions/16789288/java-lang-outofmemoryerror-unable-to-create-new-native-thread. So the question is how big the thread pool is? – Thomas Kläger Feb 23 '16 at 05:48
  • 2
    `sun.misc.Unsafe.park` is used by the JVM to let waiting threads sleep. I do not think this is related to the `OutOfMemoryError` you are getting. – MartinS Feb 23 '16 at 05:48
  • @ThomasKläger even I thought of the same solution, but now I am trying to find out the point of instantiation of these threads, so I could optimize my program. – agasthya_tadakamalla Feb 23 '16 at 08:41
  • Somewhere there must be calls that create (one or several) ThreadPoolExecutor - either directly by invoking `new ThreadPoolExecutor(...)` or by calling `Executors.newXYThreadPool()`. Check the parameters of these calls, since they define how large the thread pools can grow. – Thomas Kläger Feb 23 '16 at 19:08

0 Answers0