The following thread runs on a button click.
open.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
calls();
}
});
private void calls() {
Thread t = new Thread(this);
t.start();
}
@Override
public void run() {
reads();
}
public void reads() {
....
....
counter++;
// The Thread should stop here right>
}
But it doesn't end there. I am using thread.stop()
to stop the thread there. I know the range the counter has to go. I display counter value in UI. If I click the open button once the counter reaches the end state, then it shows an Interrupted
exception.