我的计划是这样的:Java线程:“加入”冻结了我的计划
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)该程序在我的电脑上运行良好。但是当我运行它时抛出了一个'ssh -X remote.host.org'连接,所有这一切都非常缓慢,并且在调用thread.join()时程序被冻结。我用'interrupt()'替换'join',程序不再冻结。为什么?我应该担心,当调用interrupt()时,关闭迭代器的'finally'语句没有被调用?
2)我应该用 'Thread.isInterrupted()' 而不是我的布尔 '中止'?
感谢
UPDATE:我放弃旗标记有波动。不改变冻结状态。
您的格式化风格使得它很难快速阅读代码:-( – 2009-10-07 08:10:35