Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8290196

12.8: Clarify the definition of program exit



    • Enhancement
    • Resolution: Fixed
    • P4
    • 20
    • 19
    • specification


      Program exit is best described in terms of the threads in a Java program, but there is an extralinguistic nature to program exit that makes it tricky to specify in the JLS. Notably, the Java API makes a distinction between daemon threads and non-daemon threads that is material to program exit but is not mentioned elsewhere in the JLS, resulting in 12.8 referring to "... threads that are *not daemon threads* ..." without explanation or context.

      In addition, 12.8 refers to the `Runtime.exit` and `System.exit` methods whose behavior since Java 1.3 has been deeply intertwined with a third kind of thread, shutdown hooks. 12.8 was last updated in the JLS Second Edition, prior to Java 1.3, so it omits any reference to shutdown hooks despite them being ordinary Java code and thus part of the program. It would be appropriate for 12.8 to recognize the role that shutdown hooks play at program exit. (From the perspective of the program's other threads -- in contrast to the API specification of shutdown hooks which is focused on the behavior of the Java Virtual Machine as it shuts down. Focusing on the program, not the JVM, has been the goal ever since 12.8 "Program Exit" was itself recast from 12.9 "Virtual Machine Exit" in the JLS First Edition.)

      Finally, 12.8 says that threads "terminate". This makes no distinction between (i) a thread that exits naturally, due to having completed execution of its `run` method, and (ii) a thread that is forcefully destroyed when the JVM halts at the end of its shutdown procedure. In (i), `finally` clauses and uncaught exception handlers get to execute; in (ii), they don't. 12.8 has always been pleasingly short but this brevity is a liability when it comes to giving a thorough account of what Java programmers can expect.


        Issue Links



              abuckley Alex Buckley
              abuckley Alex Buckley
              0 Vote for this issue
              4 Start watching this issue