Read the official API docs again ! First of all, the interrupt() does NOT stop a thread !
interrupt() does special actions *ONLY* if the thread to be interrupted is in a waiting state, i.e. in wait(), join(), sleep(), blocked in a nio Selector or in a blocking IO operation (reading from a plain socket). If none of above applies, then interrupt just sets the interrupted flag, nothing else. If you want to stop a thread, use the stop() method. Although it's deprecated, it still works, and if you don't care about consequences, you can use it to immediately stop the thread. Please keep in mind, that if you have a thread running and stopped or finished, you can't start it again ! you need to create a new thread and start that one. Last, why don't you use the simple approach I've described you in my last email to you ? It's 100% foolproof and it's more secure to start/stop a behavior than a thread, especially if you don't know how to use threads. Just put the code from your cam thread in the behavior.processStimulus() method, then replace cam.isInterrupted() with behavior.isEnabled(), cam.start() with behavior.setEnabled(true) and cam.interrupt() with behavior.setEnabled(false). More than that, behaviors are part of the scene graph and consequently you can use many of the automatic logic encapsulated in a behavior, like the scheduling region or scheduling interval. Cheers, Florin -----Original Message----- From: Discussion list for Java 3D API [mailto:[EMAIL PROTECTED] Behalf Of Andy Sent: Donnerstag, 29. April 2004 04:19 To: [EMAIL PROTECTED] Subject: [JAVA3D] Stopping a thread I have a question of stopping a thread. I studied the API that I know that the interrupt will stop a thread. But here is my code: public void mouseMoved(MouseEvent e){ if(e.getX() <= 1 || e.getX() >= boundary.width - 1 || e.getY() <= 1 || e.getY() >= boundary.height - 1){ // Update the mouse position in the camera before starting or checking the thread camera.setMousePosition(e.getX(), e.getY()); if(cam.isInterrupted()){ camera.setChecking(true); cam.start(); System.out.println("Camera is start()" + e.getX() + ":" + e.getY()); } }else{ camera.setMousePosition(e.getX(), e.getY()); if(!cam.isInterrupted()){ camera.setChecking(false); try{ cam.interrupt(); }catch(Exception exception){} System.out.println("Camera is interrupt()" + e.getX() + ":" + e.getY()); } } } As you can see that if the isInterrupted() returns false in the else statement, then it will interrupt the thread, which implies that the thread is alive and still running so it will interrupt the thread, right? but everytime I have mouseMoved() detected, it checks if the mouse pointer is in the area or not, if it is, checks if it is interrupted or not, if it is interrupted or not, if it is interrupted, which means it should start the thread again; if it is not interrupted, which means it's running, it will interrupt. But whenever I move my mouse in the area, it starts the thread, then once I interrupt the thread, no matter where I move(exception the area I wanna do something with, which will start the thread), it just goes into the if statement showing "Camera is interrupted()" Any hints? Many thanks, Andy =========================================================================== To unsubscribe, send email to [EMAIL PROTECTED] and include in the body of the message "signoff JAVA3D-INTEREST". For general help, send email to [EMAIL PROTECTED] and include in the body of the message "help". =========================================================================== To unsubscribe, send email to [EMAIL PROTECTED] and include in the body of the message "signoff JAVA3D-INTEREST". For general help, send email to [EMAIL PROTECTED] and include in the body of the message "help".
