Making a beep sound from my java program appears to create a thread that continues to use some (about 3%) CPU forever after the beep has stopped - even though the rest of the program remains idle.
I'm running on Linux (Ubuntu) and using PulseAudio .
I can get around this problem by suspending and resuming the pulseaudio thread (see below) but that is pretty nasty since suspend & resume are deprecated.
Can anyone tell me what is wrong with my code, or how to better solve the problem, or is it a bug in the pulseaudio code?
Thanks for any help.

public static void beep1(int hz,int msecs) {
try {
// Borrowed from somewhere on the web. Apologies to the author for not providing a link. Lost it.
byte[] buf = new byte[msecs*8];
for (int i=0; i<buf.length; i++) {
double angle = i / (41000.0 / hz) * 2.0 * Math.PI;
buf[i] = (byte)(Math.sin(angle) * 80.0);
}
AudioFormat af = new AudioFormat(44100.0F,16,2,true,false);
SourceDataLine sdl = AudioSystem.getSourceDataLine(af);
sdl.open(af);
sdl.start();
sdl.write(buf,0,buf.length);
sdl.drain();
sdl.close();
sdl.stop();
} catch (Exception e) {
e.printStackTrace();
}
}

public static void main(String[] args) {
try {
beep1(700,20000);
Thread.sleep(60000);
beep1(700,20000);
} catch (Exception e) {
e.printStackTrace();
}
}

After the first beep, CPU continues to be used, even though the program is apparently idle.

If I then add:

private static Thread pulseThread ;
public static void beep2(int hz,int msecs) {
try {
if (pulseThread!=null) pulseThread.resume();

beep1(hz,msecs);

if (pulseThread==null) {
Map<Thread,StackTraceElement[]> threads=Thread.getAllStackTraces();
for (Thread t: threads.keySet()) {
StackTraceElement[] ste=threads.get(t);
if (ste.length>0 && ste[0].toString().startsWith("org.classpath.icedtea.puls eaudio")) {
pulseThread=t;
break;
}
}
}
pulseThread.suspend();
} catch (Exception e) {
e.printStackTrace();
}
}

...and change main to use beep2 rather than beep1:

public static void main(String[] args) {
try {
beep2(700,20000);
Thread.sleep(60000);
beep2(700,20000);
} catch (Exception e) {
e.printStackTrace();
}
}

Now, no CPU isused between the beeps.

So what is going on?
How can I avoid the unnecessary CPU use without using deprecated code?
Thanks.

java version "1.7.0_09"
OpenJDK Runtime Environment (IcedTea7 2.3.3) (7u9-2.3.3-0ubuntu1~12.10.1)
OpenJDK 64-Bit Server VM (build 23.2-b09, mixed mode)

Same issue on 32 bit version.