Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #35848
| Newsgroups | comp.lang.java.programmer |
|---|---|
| Date | 2016-10-20 05:27 -0700 |
| References | <6628a02c-9c5a-4cdc-8113-fcf13c972ea4@googlegroups.com> |
| Message-ID | <17cd471e-65d9-47ed-b616-be748efd8fec@googlegroups.com> (permalink) |
| Subject | Re: Interrupt code while running (from Form) |
| From | Eric Douglas <e.d.programmer@gmail.com> |
On Thursday, October 20, 2016 at 4:45:19 AM UTC-4, jkl wrote:
> ... The trouble is, even running in Netbeans, the only way to interrupt it while running is to go outside the form and use the Stop button in Netbeans IDE. I have put a stop button on the form but however many times I click it while the code's running - it's being ignored.
>
I don't use Netbeans but to stop a background thread normally you interrupt it, then it has to care that it's interrupted..
Thread rt = new Thread() {
int count = 0;
@Override
public void run() {
while (true) {
if (Thread.interrupted()) {
break;
}
if (count == Integer.MAX_VALUE) {
count = 0;
} else {
count++;
}
System.out.println(count);
}
}
};
JFrame f = new JFrame();
f.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
JButton b = new JButton("Stop it");
f.getContentPane().add(b);
rt.start();
b.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent arg0) {
rt.interrupt();
}
});
f.pack();
f.setVisible(true);
If you run something from the IDE then you think you closed out but the IDE shows your test still running, go to your JDK install folder, to it's bin folder, and run the jvisualvm.exe. Double click your process, go to the Threads tab, and click the Thread Dump button.
Back to comp.lang.java.programmer | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Interrupt code while running (from Form) jkl <euclidalgorithm@gmail.com> - 2016-10-20 01:44 -0700
Re: Interrupt code while running (from Form) Nigel Wade <nmw@local.domain> - 2016-10-20 10:33 +0100
Re: Interrupt code while running (from Form) Eric Douglas <e.d.programmer@gmail.com> - 2016-10-20 05:27 -0700
Re: Interrupt code while running (from Form) Nigel Wade <nmw@local.domain> - 2016-10-20 16:01 +0100
Re: Interrupt code while running (from Form) Eric Douglas <e.d.programmer@gmail.com> - 2016-10-20 08:47 -0700
Re: Interrupt code while running (from Form) Nigel Wade <nmw@local.domain> - 2016-10-20 17:49 +0100
Re: Interrupt code while running (from Form) Eric Douglas <e.d.programmer@gmail.com> - 2016-10-20 10:17 -0700
Re: Interrupt code while running (from Form) Nigel Wade <nmw@local.domain> - 2016-10-21 15:38 +0100
Re: Interrupt code while running (from Form) Nigel Wade <nmw@local.domain> - 2016-10-21 16:38 +0100
Re: Interrupt code while running (from Form) lewbloch@gmail.com - 2016-10-22 16:18 -0700
csiph-web