From f270b450844f40ffed4282869f2812d1dbd41f06 Mon Sep 17 00:00:00 2001 From: Starla Insigna Date: Mon, 16 Feb 2009 13:19:13 -0500 Subject: Engine: Reduced thread pollution Because of the frequent Sequencer reinitalization, many shutdown hook threads designed to close the Sequencer upon exit were created, which polluted the environment with many unneeded thread. To solve this, the shutdown hook is now only created the first time the Sequencer is initalized. --- src/com/fourisland/fourpuzzle/Audio.java | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) (limited to 'src/com/fourisland') diff --git a/src/com/fourisland/fourpuzzle/Audio.java b/src/com/fourisland/fourpuzzle/Audio.java index 3283c68..3f863e1 100755 --- a/src/com/fourisland/fourpuzzle/Audio.java +++ b/src/com/fourisland/fourpuzzle/Audio.java @@ -24,6 +24,7 @@ import javax.sound.sampled.Clip; public class Audio { private static Sequencer seq; + private static boolean firstInit = false; public static void init() { @@ -31,15 +32,20 @@ public class Audio { seq = MidiSystem.getSequencer(); seq.open(); - Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() { - public void run() { - if (seq.isRunning()) { - seq.stop(); - } + if (!firstInit) + { + Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() { + public void run() { + if (seq.isRunning()) { + seq.stop(); + } - seq.close(); - } - })); + seq.close(); + } + })); + + firstInit = true; + } } catch (MidiUnavailableException ex) { Logger.getLogger(Audio.class.getName()).log(Level.SEVERE, null, ex); } -- cgit 1.4.1