detectionThread = new Thread(new Runnable() { public void run() { while(detectionThread != null) { //if(xboxFinder.processPacket(-1, handler) == 0 && !isLiveCapture) { if(xboxFinder.processPacket(-1, handler) == 0 && !isSearching) { stopDetectionThread(); } Thread.yield(); } System.out.println("thread exit"); xboxFinder.breakLoop(); } });