JDK-4365713 : JavaSound EventDispatcher thread never exits
  • Type: Bug
  • Component: client-libs
  • Sub-Component: javax.sound
  • Affected Version: 1.3.0
  • Priority: P3
  • Status: Closed
  • Resolution: Won't Fix
  • OS: generic
  • CPU: generic
  • Submitted: 2000-08-25
  • Updated: 2001-04-02
  • Resolved: 2001-04-02
Related Reports
Relates :  
Relates :  
Description

Name: kb87695			Date: 08/24/2000


Run this class with parameter being the name of an audio file.


import java.applet.Applet;
import java.applet.AudioClip;
import java.net.URL;
import java.net.MalformedURLException;

class AudioTest {

        URL        urlBell1;
        AudioClip  aclip;

        AudioTest (String audioFile) {
                try {
                        this.urlBell1 = new URL( "file", "", audioFile );
                } catch ( MalformedURLException ex ) {
                        ex.printStackTrace();
                        System.exit( 255 );
                }
                this.aclip = Applet.newAudioClip( this.urlBell1 );
                this.aclip.play();

                try {
                        Thread.sleep( 1 * 1000 );
                } catch ( InterruptedException ex ) {
                        ex.printStackTrace();
                        System.exit( 255 );
                }
        }
        public static void main( String[] args ) {
                new AudioTest(args[0]);
        }
}



====================================================
Stack Trace:
====================================================

Finalizer:
  [1] java.lang.Object.wait (native method)
  [2] java.lang.ref.ReferenceQueue.remove (ReferenceQueue.java:108), pc =
48
  [3] java.lang.ref.ReferenceQueue.remove (ReferenceQueue.java:123), pc = 2

  [4] java.lang.ref.Finalizer$FinalizerThread.run (Finalizer.java:162), pc
= 6
Reference Handler:
  [1] java.lang.Object.wait (native method)
  [2] java.lang.Object.wait (Object.java:420), pc = 2
  [3] java.lang.ref.Reference$ReferenceHandler.run (Reference.java:110), pc
= 49
Signal dispatcher:
Thread-0:
  [1] java.lang.Object.wait (native method)
  [2] java.lang.Object.wait (Object.java:420), pc = 2
  [3] com.sun.media.sound.EventDispatcher.dispatchEvents
(EventDispatcher.java:144), pc = 10
  [4] com.sun.media.sound.EventDispatcher.run (EventDispatcher.java:195),
pc = 4
Headspace mixer frame proc thread:
  [1] java.lang.Thread.sleep (native method)
  [2] com.sun.media.sound.MixerThread.runNative (native method)
  [3] com.sun.media.sound.MixerThread.run (MixerThread.java:317), pc = 30
(Review ID: 108571) 
======================================================================

Comments
EVALUATION michael.bundschuh@Eng 2000-10-09 Not a P1 bug. Change to P3, and commit for Merlin. michael.bundschuh@Eng 2001-04-02 Closing as will not fix, based on the statement below given to HP during a bug escalation. ----------------------------------------------------------------------- Statement from JavaSound Engineering ----------------------------------------------------------------------- It is our engineering assessment that we should not attempt to make code changes to address "bug id# 4365713: JavaSound EventDispatcher thread never exits." The AudioClip interface does not specify whether the VM should or should not exit after the clip is fully played. So no assumptions should be made by the application programmer about that behavior. Changing code in the JavaSound engine will change the audio behavior from J2SE 1.2, something we would not do lightly and would have to publish properly so application developers can make the appropriate changes in their code. We considered, and then decided against, two possible code changes to address this issue: The first proposed solution -- making EventDispatcher a daemon thread -- is not enough because it would cause the playing sound to be truncated if the program exits before the sound is fully played. The second proposed solution -- killing the EventDispatcher thread once the clip is finished playing -- could kill other audio clips and DataLines before they are finished doing what they are doing. Is there some reason HP cannot use the following solutions in the user's application? 1. Stop using the AudioClip interface, which was poorly designed. Use the Java Sound API instead. 2. Know the length of the clip in advance and call System.exit() after Sleeping for the required duration. 3. If knowing the clip duration in advance is not possible, use the JavaSound Clip interface to open a clip, get its duration and sleep for the required duration before explicitly exiting the VM. Refer to the Juke.java program in the JDK 1.3 demo directory. 4. Attach a javax.sound.sampled.LineListener to the audio clip. When a clip is done playing a number of times, it throws a close event where the application developer can call System.exit(0). In addition to the technical aspects of this problem, there is one critical business issue that should be considered: Based on the current JavaSound engine design and behavior, application developers have been using application solutions like the ones listed above since the release of J2SE 1.2.0. If Sun was to change the current behavior, to force thread exit, the applications developed since 1.2.0 would no longer run as implemented. This would cause a large problem for the overall java user base. For this reason, Sun's business position is that this change should not be made to the behavior of the JavaSound engine. -----------------------------------------------------------------------
11-06-2004

WORK AROUND ====================================================================== Name: kb87695 Date: 08/24/2000 A workaround to this bug is to change the EventDispatcher Thread to a Daemon Thread. In /com/sun/media/sound/AbstractLine.java Add the following line after line 52. eventDispatcher = new EventDispatcher(); eventDispatcher.setDaemon(true); // Add this line eventDispatcher.start(); In /com/sun/media/sound/AbstractMidiDevice.java Add the following line after line 81. eventDispatcher = new EventDispatcher(); eventDispatcher.setDaemon(true); // Add this line eventDispatcher.start(); *NOTE: We are unsure what, if any, code this breaks. ====================================================================== michael.bundschuh@Eng 2001-04-02 [Note -- this is not a good workaround, since it requires source code modification and the sound can get truncated if the app exits before the sound stops playing. Try the suggestions below.] Here are some suggestions to working around this behavior. 1. Stop using the AudioClip interface, which was poorly designed. Use the Java Sound API instead. 2. Know the length of the clip in advance and call System.exit() after Sleeping for the required duration. 3. If knowing the clip duration in advance is not possible, use the JavaSound Clip interface to open a clip, get its duration and sleep for the required duration before explicitly exiting the VM. Refer to the Juke.java program in the JDK 1.3 demo directory. 4. Attach a javax.sound.sampled.LineListener to the audio clip. When a clip is done playing a number of times, it throws a close event where the application developer can call System.exit(0). ======================================================================
11-06-2004

PUBLIC COMMENTS JavaSound EventDispatcher thread never exits
10-06-2004