【发布时间】:2015-10-13 06:11:21
【问题描述】:
我的 java swing 程序有些问题。当ExportWithoutEntryPointFrm Frame 出现在自己的线程中时,我尝试停止我的主 Frame 线程。
我用java.util.concurrent.Semaphore 实现了它。
出现的 Frame 只显示一个空 Frame,按钮、标签等不会显示,并且两个线程都被阻塞。我认为有一个死锁,但我没有找到它。
我的新警告框架代码,将从主框架调用:
public class ExportWithoutEntryPointFrm extends javax.swing.JFrame implements Runnable
{
private Semaphore sema;
private boolean decision = false;
public ExportWithoutEntryPointFrm(Semaphore semaphore)
{
initComponents();
this.setLocationRelativeTo(null);
this.sema = semaphore;
}
@Override
public void run()
{
this.setVisible(true);
try
{
sema.acquire();
}
catch (InterruptedException e)
{
this.decision = false;
this.sema.release();
this.setVisible(false);
}
}
}
以及来自主框架的调用代码:
Semaphore waitForDecisionSema = new Semaphore(1, true);
ExportWithoutEntryPointFrm warningFrm = new ExportWithoutEntryPointFrm(waitForDecisionSema);
warningFrm.run();
waitForDecisionSema.acquire();
【问题讨论】:
标签: java swing concurrency semaphore