I\'m using a thread that is continuously reading from a queue.
Something like:
public void run() {
    Object obj;
    while(true) {
        synchron         
        
I usually put a flag in the class that has the Thread in it and in my Thread code I would do. (NOTE: Instead of while(true) I do while(flag))
Then create a method in the class to set the flag to false;
private volatile bool flag = true;
public void stopThread()
{
   flag = false;
}
    public void run() {
        Object obj;
        while(flag) {
            synchronized(objectsQueue) {
                if(objectesQueue.isEmpty()) {
                    try {
                        objectesQueue.wait();
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                    obj = objectesQueue.poll();
                }
            }
            // Do something with the Object obj
        }
    }