|
Quick Lists
|
|
Bug ID:
|
4365713
|
|
Votes
|
0
|
|
Synopsis
|
JavaSound EventDispatcher thread never exits
|
|
Category
|
java:classes_sound
|
|
Reported Against
|
1.3
|
|
Release Fixed
|
|
|
State
|
11-Closed,
Will Not Fix,
bug
|
|
Priority:
|
3-Medium
|
|
Related Bugs
|
4735740
,
5070730
|
|
Submit Date
|
25-AUG-2000
|
|
Description
|
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)
======================================================================
|
|
Work Around
|
======================================================================
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.
======================================================================
xxxxx@xxxxx 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).
======================================================================
|
|
Evaluation
|
xxxxx@xxxxx 2000-10-09
Not a P1 bug. Change to P3, and commit for Merlin.
xxxxx@xxxxx 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.
-----------------------------------------------------------------------
|
|
Comments
|
Submitted On 26-SEP-2001
thanhlong
Long Kendy you have message from Javasound
Submitted On 04-AUG-2004
jpyeron
add the following, it will not change current function, but allow proper resource clean up.
public EventDispatcher AudioSystem.getEventDispatcher();
EventDispatcher
{
/**
*
* Dispose will destroy the event dispatcher thread, and dump its resources.
*
* It is illegal to dispose while audio is rendering, etc.
* It is also illegal to dispose whilst listeners are still enqueued
**/
public void dispose() throws IllegalStateException;
public EventListener[] getEventListeners();
}
PLEASE NOTE: JDK6 is formerly known as Project Mustang
|
|
|
 |