JDK-4631192 : STOP LineEvent not always generated when playing a Clip
  • Type: Bug
  • Component: client-libs
  • Sub-Component: javax.sound
  • Affected Version: 1.4.0_01
  • Priority: P4
  • Status: Open
  • Resolution: Unresolved
  • OS: linux_redhat_7.1
  • CPU: x86
  • Submitted: 2002-01-31
  • Updated: 2021-07-13
Related Reports
Relates :  
Relates :  
Description
SYMPTOM
--------
When playing a number of Clips in a row, the system will eventually hang. Attached is some java code that shows the hang on our systems.  The code is fairly straight forward:

   for ( ) {
           Start playing a clip
           wait for notify
    }
  Clip LineListener() {
    on STOP sleep a bit then close the clip
    on CLOSE notify
 }


CAUSE
------
Sometimes we will fail to receive the STOP event. Since the STOP event handler is responsible for closing the clip, we never get a chance to close it, and will end up waiting forever for the clip to close.

The longer I make the delay before the clip is closed, the less frequently this happens.   

I've attached the java code, and the thread stack trace after a hang.   

 
EXAMPLE
-------
import javax.sound.sampled.*;

public class AudioHangDemo {
    private Clip clip;
    private int count = 1;

    
    public void playClip() throws Exception {
		// test.wav is any short (1 second) wave file
	AudioInputStream audioInputStream =
            AudioSystem.getAudioInputStream(new java.io.File("test.wav"));
	DataLine.Info info = 
		new DataLine.Info(Clip.class, audioInputStream.getFormat());
	clip = (Clip) AudioSystem.getLine(info);
	
	clip.addLineListener(new LineListener() {
		public void update(LineEvent e) {
		    if (e.getType() == LineEvent.Type.STOP) {
		        System.out.println("STOP");
			try {
			    Thread.sleep(50);
			} catch (InterruptedException ie) {}
			clip.close();
		    }
		    else if (e.getType() == LineEvent.Type.CLOSE) {
		        System.out.println("CLOSE");
			synchronized(AudioHangDemo.this) {
			    AudioHangDemo.this.notify();
			}
		    }
		    else if (e.getType() == LineEvent.Type.START) {
		        System.out.println("START");
		    }
		}
	    });

	clip.open(audioInputStream);
	System.out.println(" ---------- start " + count + " --------");
	clip.start();

	System.out.println("waiting ... ");
	synchronized(this) {
	    wait();
	}
	System.out.println("... done");
	count++;
    }

    public static void main(String[] args) throws Exception {
	AudioHangDemo ahd = new AudioHangDemo();

	for (int i = 0; i < 1000; i++) {
	    ahd.playClip();
	}

	System.exit(0);
    }
}

 
STACK DUMP
---------------
Full thread dump Java HotSpot(TM) Client VM (1.4.0-rc-b91 mixed mode):

"Headspace mixer frame proc thread" daemon prio=1 tid=0x0x813c7b8 nid=0x1214 waiting on monitor [4c796000..4c79686c]
        at java.lang.Thread.sleep(Native Method)
        at com.sun.media.sound.MixerThread.runNative(Native Method)
        at com.sun.media.sound.MixerThread.run(MixerThread.java:314)

"Java Sound event dispatcher" prio=1 tid=0x0x813a210 nid=0x1213 waiting on monitor [4c6ae000..4c6ae86c]
        at java.lang.Object.wait(Native Method)
        - waiting on <0x445f9d38> (a com.sun.media.sound.EventDispatcher)
        at java.lang.Object.wait(Object.java:426)
        at com.sun.media.sound.EventDispatcher.dispatchEvents(EventDispatcher.java:294)
        - locked <0x445f9d38> (a com.sun.media.sound.EventDispatcher)
        at com.sun.media.sound.EventDispatcher.run(EventDispatcher.java:345)
        at java.lang.Thread.run(Thread.java:536)

"Signal Dispatcher" daemon prio=1 tid=0x0x807bc50 nid=0x1211 waiting on monitor [0..0]

"Finalizer" daemon prio=1 tid=0x0x8074578 nid=0x120e waiting on monitor [4c2e2000..4c2e286c]
        at java.lang.Object.wait(Native Method)
        - waiting on <0x445ea290> (a java.lang.ref.ReferenceQueue$Lock)
        at java.lang.ref.ReferenceQueue.remove(ReferenceQueue.java:111)
        - locked <0x445ea290> (a java.lang.ref.ReferenceQueue$Lock)
        at java.lang.ref.ReferenceQueue.remove(ReferenceQueue.java:127)
        at java.lang.ref.Finalizer$FinalizerThread.run(Finalizer.java:159)

"Reference Handler" daemon prio=1 tid=0x0x8073930 nid=0x120d waiting on monitor [4c261000..4c26186c]
        at java.lang.Object.wait(Native Method)
        - waiting on <0x445ea2f8> (a java.lang.ref.Reference$Lock)
        at java.lang.Object.wait(Object.java:426)
        at java.lang.ref.Reference$ReferenceHandler.run(Reference.java:113)
        - locked <0x445ea2f8> (a java.lang.ref.Reference$Lock)

"main" prio=1 tid=0x0x80515d8 nid=0x120a waiting on monitor [bfffd000..bfffd6fc]
        at java.lang.Object.wait(Native Method)
        - waiting on <0x445ea310> (a AudioHangDemo)
        at java.lang.Object.wait(Object.java:426)
        at AudioHangDemo.playClip(AudioHangDemo.java:40)
        - locked <0x445ea310> (a AudioHangDemo)
        at AudioHangDemo.main(AudioHangDemo.java:50)

"VM Thread" prio=1 tid=0x0x80707b0 nid=0x120c runnable 

"VM Periodic Task Thread" prio=1 tid=0x0x807a778 nid=0x120f waiting on monitor 
"Suspend Checker Thread" prio=1 tid=0x0x807b1d8 nid=0x1210 runnable 

CONFIGURATION
-------------
java version "1.4.0-rc"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.0-rc-b91)
Java HotSpot(TM) Client VM (build 1.4.0-rc-b91, mixed mode)

I am running on RedHat 7.2, no ALSA, emu10k sound.

Comments
EVALUATION Could not reproduce with ALSA. Will try with OSS only.
20-10-2005

CONVERTED DATA BugTraq+ Release Management Values COMMIT TO FIX: dragon
14-06-2004

EVALUATION ###@###.### 2002-02-14 Cause is not known. Needs more investigation. ###@###.### 2002-04-23 Not enough time to fix for Hopper. It may be fixed along with other related fixes. Needs verification. Push to Mantis. ###@###.### 2002-10-29 Could not reproduce this bug on Redhat 7.3, ALSA 0.9rc3 installed. Contacted submitter if the problem still persists. Should also be no problem with the ALSA implementation. ###@###.### 2002-11-06 Since time is running out for mantis and I'm unable to reproduce, I'll commit to Tiger. It is indeed possible that this problem got fixed with other fixes and clean-ups in the Java Sound implementation. New testing, still could not reproduce. Leave it in for dragon time frame.
11-06-2004

PUBLIC COMMENTS STOP LineEvent not always generated when playing a Clip
10-06-2004