On Sat, 24 May 2025 03:22:41 GMT, Sergey Bylokhov <s...@openjdk.org> wrote:
> > For me, once the end of "main()" is reached the VM exits. Even if a sound > > is playing and looping. > > And even then, are you suggesting this would block System.exit() ? > > Where have you actually seen this problem or why are you sure it is a > > problem ? > > It does not prevent the application from exiting via `System.exit()`, but it > does prevent it from exiting naturally when the main method completes. This > is consistent with how AWT behaves (as [documented > here](https://github.com/openjdk/jdk/blob/fdda7661906eab63d939e9f482449e21cc143c8f/src/java.desktop/share/classes/java/awt/doc-files/AWTThreadIssues.html#L108)): > the application should dispose of all Windows/Frames to be shutdown. > > Similarly, this new API appears to follow the same logic: all playable clips > must be stopped, otherwise the application will keep running indefinitely. > > I tested this behavior on macOS using [this MIDI > file](https://en.wikipedia.org/wiki/File:MIDI_sample.mid?oldformat=true). > > ``` > import java.io.File; > > import javax.sound.SoundClip; > > public final class TestClip { > public static void main(String[] args) throws Exception { > SoundClip soundClip = SoundClip.createSoundClip(new > File("MIDI_sample.mid")); > soundClip.loop(); > System.out.println("end main"); > } > } > ``` So it seems it varies depending on content-type. This midi case creates a DataPusher which creates a non-daemon thread. pushThread = JSSecurityManager.createThread(this, "DataPusher", // name false, // daemon <<<<<<<<<<<<<< -1, // priority true); // doStart DataPusher is only used by JavaAudioSoundClip although that is used by a few content handlers as well as the *Clip APIs. Other than this only MidiInDevice creates a non-daemon thread and that won't be used by SoundClip So I am sure it is possible to pass in a parameter to tell DataPusher it should use a daemon thread for this case - leaving other cases unaffected - and then we'd consistently terminate and can remove all the words in the javadoc about this. Take a look at the commit I am pushing now - updates the implementation but not (yet) revising the javadoc. ------------- PR Comment: https://git.openjdk.org/jdk/pull/24991#issuecomment-2906952672