View Single Post
  #1 (permalink)  
Old 08-29-2008, 01:28 AM
willemjav willemjav is offline
Senior Member
 
Join Date: Dec 2007
Location: Spain
Posts: 342
willemjav is on a distinguished road
how to stop a thread
Threads are tricky! You start them easily.. but how do you stop them. Consider this example (it works more or the less) but each time I test the pedal a new thread is started.... so what are all these started threats doing:



Code:
class PedaltestThread extends Thread { private int cnt; // The name of this thread. public PedaltestThread(int cnt) { // the thread counter this.cnt = cnt; } public void run() { midipedalflag=false; // the flag set by midipedal do { // and space bar } while (!midipedalflag); midipedalflag=false; midipedalTest.setSelected(false); System.out.println(" pedal pushed " + cnt); } } private class EventHandler implements ActionListener { public void actionPerformed(ActionEvent evt) { Object source = evt.getSource(); if (source == midipedalTest) { if (midipedalTest.isSelected()) { threadcount++; // thread counter pedtest = new PedaltestThread(threadcount); pedtest.start(); } if (!midipedalTest.isSelected()) { } }
Reply With Quote
Sponsored Links