summary refs log tree commit diff stats
path: root/src
diff options
context:
space:
mode:
authorStarla Insigna <hatkirby@fourisland.com>2009-02-16 13:19:13 -0500
committerStarla Insigna <hatkirby@fourisland.com>2009-02-16 13:19:13 -0500
commitf270b450844f40ffed4282869f2812d1dbd41f06 (patch)
tree4dde71f830d1d2be2d1189a4dfc34f177c326545 /src
parent0540ce566ddce97a60c3279c51d5c5ddf1645321 (diff)
downloadfourpuzzle-f270b450844f40ffed4282869f2812d1dbd41f06.tar.gz
fourpuzzle-f270b450844f40ffed4282869f2812d1dbd41f06.tar.bz2
fourpuzzle-f270b450844f40ffed4282869f2812d1dbd41f06.zip
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.
Diffstat (limited to 'src')
-rwxr-xr-xsrc/com/fourisland/fourpuzzle/Audio.java22
1 files changed, 14 insertions, 8 deletions
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;
24public class Audio { 24public class Audio {
25 25
26 private static Sequencer seq; 26 private static Sequencer seq;
27 private static boolean firstInit = false;
27 28
28 public static void init() 29 public static void init()
29 { 30 {
@@ -31,15 +32,20 @@ public class Audio {
31 seq = MidiSystem.getSequencer(); 32 seq = MidiSystem.getSequencer();
32 seq.open(); 33 seq.open();
33 34
34 Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() { 35 if (!firstInit)
35 public void run() { 36 {
36 if (seq.isRunning()) { 37 Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() {
37 seq.stop(); 38 public void run() {
38 } 39 if (seq.isRunning()) {
40 seq.stop();
41 }
39 42
40 seq.close(); 43 seq.close();
41 } 44 }
42 })); 45 }));
46
47 firstInit = true;
48 }
43 } catch (MidiUnavailableException ex) { 49 } catch (MidiUnavailableException ex) {
44 Logger.getLogger(Audio.class.getName()).log(Level.SEVERE, null, ex); 50 Logger.getLogger(Audio.class.getName()).log(Level.SEVERE, null, ex);
45 } 51 }