Q: Java Threads, with Visual and Audio I am creating a small Java application which needs to connect to a peripheral consistantly, A Leap Motion, and then also display visual feedback. I also am trying to play a series of sounds based on user input through, the Leap Motion... Basically just when a certain value is greater than a minimum, play a sound..
What I specifically need help doing is how to properly handle threads in Java, and if I need to manually close them...
To start up the visual display using LWJGL I start a thread like so:
Runnable newWindow = new ThreadedWindow();
new Thread(newWindow).start();

The Threaded Window Class consists of a run function:
CreateWindow mainWindow = new CreateWindow();
mainWindow.startWindow();

The startWindow function just does very basic OpenGL stuff to create a blank window. I would just like to know if this is the right way to create and use a thread for a window, or if there is some other more efficient way to do this.
public class CreateWindow {

private int windowW = 1280;
private int windowH = 720;
private int windowCentreX = windowW/2;
private int windowCentreY = windowH/2;

public void startWindow()
{
    try {
        Display.setDisplayMode(new DisplayMode(1280,720));
        Display.create();
    } catch (LWJGLException e) {
        e.printStackTrace();
        System.exit(0);
    }

    //Init OpenGL Stuff
    GL11.glMatrixMode(GL11.GL_PROJECTION);
    GL11.glLoadIdentity();
    GL11.glOrtho(0, 1280, 0, 720, 1, -1);
    GL11.glMatrixMode(GL11.GL_MODELVIEW);

    while(!Display.isCloseRequested()) {
        //Render the OpenGL Stuff
        GL11.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT); 

        // set the color of the quad (R,G,B,A)
        GL11.glColor3f(0.5f,0.5f,1.0f);

        float circleRadius = 50;
        float circleX = FingerInfo.averageFingerX;
        float circleY = FingerInfo.averageFingerY;

        // draw quad
        GL11.glBegin(GL11.GL_QUADS);
            GL11.glVertex2f(circleX + windowCentreX,circleY + windowCentreY);
            GL11.glVertex2f(circleX + windowCentreX + circleRadius,circleY + windowCentreY);
            GL11.glVertex2f(circleX + windowCentreX + circleRadius, circleY + windowCentreY + circleRadius);
            GL11.glVertex2f(circleX + windowCentreX,circleY + windowCentreY + circleRadius);
        GL11.glEnd();

        Display.update();
    }
    Display.destroy();
}

}
-
The audio sounds I am creating use JavaX.sound.midi. Using a basic Synth and MidiChannel to create a basic tone. 
public static void GenerateTone(int newNote)
{
    note = newNote;
    try
    {
        Synthesizer synth = MidiSystem.getSynthesizer();
        synth.open();
        MidiChannel channel = synth.getChannels()[0];
        for(int i=0; i < 1; i++)
        {
            channel.noteOn(note, 50);
            System.out.println("Generating new tone!");

        }
    } catch (MidiUnavailableException e) { 
        e.printStackTrace();
    }
}

I did have this called in a run function, which was used to start a thread in a similar way to the window, however playing lots of sounds repetitively, like 10 times a second caused the sounds to pause and make a lot of buzzy noises. This could be a problem completely unrelated to the Thread however I just wanted to ask if there was a good way to play a sound in a thread. And if I need to handle the destruction of the thread after the sound is played.
Thanks :D

A: The developers of LWJGL themselves have specifically mentioned that LWJGL is limited to a single graphics context, i.e. no more than 1 OpenGL window or Display at a time. So, if you start a thread and create a second Display, something very unfortunate is likely to happen. Otherwise, assuming you're creating that window thread only once, it should be perfectly fine.
However, if you're using sound and you want to play multiple at once, since you're using LWJGL why not use LWJGL's OpenAL bindings? OpenAL is perfectly able to play multiple sounds at the same time without multithreading, although you would need to have a recorded sound to do it, you can modify the pitch in the function used to play the sound.
