Use a boolean.....e.g. in your case the handleScanButton() method must be doing some function in a loop. Initialize a boolean shouldRun to true first. Now put a check like:
handleScanButton() { while(shouldRun && <Your other conditions>) { <....your other code....> } } Now make a stopThread method in which make this boolean false.e.g. private void stopThread() { shouldRun = false; } Call this stopThread() method whenever you want to stop your thread. Hope this helps. Thanks. -Deepak. ----- Original Message ----- From: "Panagiotis Plevrakis" <[EMAIL PROTECTED]> To: "JDJList" <[EMAIL PROTECTED]> Sent: Friday, May 31, 2002 10:12 AM Subject: [jdjlist] stopping a Thread > Can anybody show me a good non-deprecated way to stop scanThread in the > following code? Setting it to null does not make her stop. What more should > I do to make her stop? > ************************************************************ > btScan.addActionListener(new ActionListener() { > public void actionPerformed(ActionEvent ae) { > btScanCounter++; > btScan.setText("Cancel Search"); > Thread t1 = new Thread() { > public void run() { > handleScanButton(); > }}; > if ((btScanCounter%2) == 0) { > scanThread = null; // THIS DOES NOT WORK > btScan.setText("Auto Search"); > } else { > if (scanThread == null) { > scanThread = new Thread(t1); > scanThread.start(); > } > } > }}); > ************************************************************ > > _________________________________________________________________ > Chat with friends online, try MSN Messenger: http://messenger.msn.com > > > To change your membership options, refer to: > http://www.sys-con.com/java/list.cfm > To change your membership options, refer to: http://www.sys-con.com/java/list.cfm