MusicThread class

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:


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?

Why do you use a thread for that?

Try it without (it’s really not necessary).

that did make the CPU usage drop down to about 20% (still not as good as 2%) when there’s not as much stuff going on the screen. But, when there’s more graphics it shoots back up to about 50%…