0

I have a Java batch which never gets finished. It invokes System.exit() at the end of the code but according to thread dump, it's blocked at Shutdown.halt0() for some reason and the batch never gets finished. What could be a cause for this?

It uses mysql-connector-java 5.1.38 and I also see a thread which is blocked at AbandonedConnectionCleanupThread.run() but I'm not sure if it has something to do with this problem.

Java version:

$ java -version
java version "1.8.0_144"
Java(TM) SE Runtime Environment (build 1.8.0_144-b01)
Java HotSpot(TM) 64-Bit Server VM (build 25.144-b01, mixed mode)

Thread dump:

Attaching to process ID 7229, please wait...
Debugger attached successfully.
Server compiler detected.
JVM version is 25.144-b01
Deadlock Detection:

No deadlocks found.

Thread 7244: (state = BLOCKED)
 - java.lang.Object.wait(long) @bci=0 (Interpreted frame)
 - java.lang.ref.ReferenceQueue.remove(long) @bci=59, line=143 (Compiled frame)
 - com.mysql.jdbc.AbandonedConnectionCleanupThread.run() @bci=16, line=43 (Interpreted frame)

Locked ownable synchronizers:
    - None

Thread 7238: (state = BLOCKED)

Locked ownable synchronizers:
    - None

Thread 7237: (state = BLOCKED)
 - java.lang.Object.wait(long) @bci=0 (Interpreted frame)
 - java.lang.ref.ReferenceQueue.remove(long) @bci=59, line=143 (Interpreted frame)
 - java.lang.ref.ReferenceQueue.remove() @bci=2, line=164 (Interpreted frame)
 - java.lang.ref.Finalizer$FinalizerThread.run() @bci=36, line=209 (Interpreted frame)

Locked ownable synchronizers:
    - None

Thread 7236: (state = BLOCKED)
 - java.lang.Object.wait(long) @bci=0 (Interpreted frame)
 - java.lang.Object.wait() @bci=2, line=502 (Interpreted frame)
 - java.lang.ref.Reference.tryHandlePending(boolean) @bci=54, line=191 (Interpreted frame)
 - java.lang.ref.Reference$ReferenceHandler.run() @bci=1, line=153 (Interpreted frame)

Locked ownable synchronizers:
    - None

Thread 7230: (state = BLOCKED)
 - java.lang.Shutdown.halt0(int) @bci=0 (Interpreted frame)
 - java.lang.Shutdown.halt(int) @bci=7, line=139 (Interpreted frame)
 - java.lang.Shutdown.exit(int) @bci=99, line=213 (Interpreted frame)
 - java.lang.Runtime.exit(int) @bci=14, line=109 (Interpreted frame)
 - java.lang.System.exit(int) @bci=4, line=971 (Interpreted frame)
 - com.example.xxx.main(java.lang.String[]) @bci=140, line=71 (Interpreted frame)

Locked ownable synchronizers:
    - None
Kohei Nozaki
  • 1,154
  • 1
  • 13
  • 36
  • Java makes a distinction between a user thread and another type of thread known as a daemon thread. The difference between these two types of threads is that if the JVM determines that the only threads running in an application are daemon threads (i.e., there are no user threads), the Java runtime closes down the application. On the other hand, if at least one user thread is alive, the Java runtime won't terminate your application. Copied from https://stackoverflow.com/questions/9651842/will-main-thread-exit-before-child-threads-complete-execution – Scary Wombat Nov 14 '18 at 06:28
  • @kohei-san, you work for an interesting company – Scary Wombat Nov 14 '18 at 06:28
  • @scary wombat thanks but is there something which indicates where I work for? – Kohei Nozaki Nov 14 '18 at 06:34

1 Answers1

0

Adding an option DONT_FAKE_MONOTONIC=1 solved the problem.

A native library called "libfaketime" was used in my app and the option seems to be a workaround. Details: https://github.com/wolfcw/libfaketime/issues/109

Kohei Nozaki
  • 1,154
  • 1
  • 13
  • 36