I have a thread class (set to minimum priority) that I'm using to play midi music in 2d platformer. When the game runs without music and the music runs without a game, they both have a very tiny CPU usage (around 2% most of the time). But, when I use the MusicThread class in my game, the CPU usage shoots up to 50-60%.
Here is the MusicThread class:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
| public class MusicThread extends Thread { public MusicThread(String filename) { super(filename); } public void run() { try{ Sequencer seqr = MidiSystem.getSequencer(); Sequence seq = MidiSystem.getSequence(new File(this.getName())); seqr.open(); seqr.setSequence(seq); seqr.start(); }catch(Exception ex){ ex.printStackTrace(); } } } |
does anyone have any suggestions to help me improve the performance?