我对Java中的多线程有点困惑,我有一个GUI,我创建了一个线程,另一个项目充当服务器并用于从其他数据源接收数据是在一个单独的线程。服务器的线程在GUI线程的一个视图中调用方法并更新状态,但GUI不更新。我怎样才能正确设置这个架构。下面是我有:从另一个线程更新GUI线程
public static void main(String[] args)
{
//Connections
Runnable r2 = new Runnable() {
@Override
public void run()
{
App.connectToServer();
}
};
//Launch main window
Runnable r1 = new Runnable() {
@Override
public void run()
{
//Installs theme
WebLookAndFeel.install();
//Launches main window
BootWindow myMainWindow = new BootWindow();
}
};
Thread thr1 = new Thread(r1);
Thread thr2 = new Thread(r2);
thr1.start();
thr2.start();
}
//Server connections
private static void connectToServer()
{
System.out.println("Connecting to the eTrade Manager Server..");
etmServer server = new etmServer();
server.connectEtmServer();
}
阅读Swing中的Oracle trail Concurency, EventDispatchThread – mKorbel 2014-10-08 15:07:24
[请阅读偶数调度线程](http://docs.oracle.com/javase/tutorial/uiswing/concurrency/dispatch.html),因为您需要更新其上的任何GUI组件。 – 2014-10-08 15:07:37
回答[这里](http://stackoverflow.com/a/26267512/230513)。 – trashgod 2014-10-08 22:35:11