My program looked like this:
class Prog
{
BufferedImage offscreen;
KindOfDatabase db;
MyThread thread;
class MyThread extends Thread
{
volatile boolean abort=false;
long lastUpdated;
public void run()
{
try
{
KindOfCursor c = db.iterator();
while(c.getNext())
{
if(abort) break;
//fill a histogram with the data,
// calls SwingUtilities.invokeAndWait every 500ms to
//do something with offscreen and update a JPanel
}
catch(Exception err)
{
err.printStackTrace();
}
finally
{
c.close();
}
}
}
void stopThread()
{
if(thread!=null)
{
thread.abort=true;
thread.join();
thread=null;
}
}
void startThread()
{
stopThread();
thread=new MyThread();
thread.start();
}
(....)
}
1) The program worked well on my computer. But when I ran it threw a 'ssh -X remote.host.org ' connection, all was very slow and the program was frozen when thread.join() was invoked. I replaced 'join' by 'interrupt()' and the program was not anymore frozen. Why ? Should I fear that, when interrupt() is called, the 'finally' statement closing the iterator was not invoked ?
2) should I use 'Thread.isInterrupted()' instead of my boolean 'abort' ?
Thanks
UPDATE: my abort flag was labelled with volatile. Doesn't change the frozen state.