因为等待远程调用的服务器返回值的响应时间较长,所以在调用远程方法之前弹出一个等待画面,但是等待画面中的"等待中....."总是无法描画出来(远程调用结束能正常关闭等待画面),怀疑与线程资源阻塞有关,于是开了一个线程弹出等待画面,还是没有解决,望高手指教!!!(部分程序如下)
---------------------------------------------------------------
// 等待画面
JDialog loadFrm;
// 开了一个线程弹出等待画面
(new waitThread("增加", "增加处理中...",nodeMngFrame)).start();
// 调用远程方法
result = nodeMngFrame.getCXNodeMngServer().addCard(cardInfo);
// 关闭等待画面
if(loadFrm != null) {
loadFrm.dispose();
}// 内部线程类waitThread
private class waitThread extends Thread {
// 父窗体
JFrame parentComp;
public waitThread(String title,String msg,JFrame parentComp) {
this.parentComp = parentComp;
loadFrm = new JDialog(parentComp,title,true);
JLabel orLabel = new JLabel(msg);
CXUtil.updateFont(orLabel);
orLabel.setPreferredSize(new Dimension(200, 80));
orLabel.setHorizontalAlignment(SwingConstants.CENTER);
orLabel.setVerticalAlignment(SwingConstants.CENTER);
loadFrm.getContentPane().add(orLabel, BorderLayout.CENTER);
loadFrm.pack();
}
public void run() {
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
int dialogWidth = 250;
int dialogHeight = 100;
loadFrm.setSize(new Dimension(dialogWidth, dialogHeight));
// 设置等待画面位置
if(parentComp != null) {
Point ppoint = parentComp.getLocation();
Dimension pdim = parentComp.getSize();
ppoint.x = ppoint.x + pdim.width/2 - dialogWidth/2;
if(ppoint.x < 0) {
ppoint.x = ppoint.x + dialogWidth/2;
}
ppoint.y = ppoint.y + pdim.height/2 - dialogHeight/2;
if(ppoint.y < 0) {
ppoint.y = ppoint.y + dialogHeight/2;
}
loadFrm.setLocation(ppoint.x , ppoint.y);
} else {
loadFrm.setLocation(screenSize.width/2-dialogWidth/2, screenSize.height/2-dialogHeight/2);
}
loadFrm.setResizable(false);
loadFrm.setCursor(new Cursor(Cursor.WAIT_CURSOR));
loadFrm.show();
}
}
---------------------------------------------------------------
// 等待画面
JDialog loadFrm;
// 开了一个线程弹出等待画面
(new waitThread("增加", "增加处理中...",nodeMngFrame)).start();
// 调用远程方法
result = nodeMngFrame.getCXNodeMngServer().addCard(cardInfo);
// 关闭等待画面
if(loadFrm != null) {
loadFrm.dispose();
}// 内部线程类waitThread
private class waitThread extends Thread {
// 父窗体
JFrame parentComp;
public waitThread(String title,String msg,JFrame parentComp) {
this.parentComp = parentComp;
loadFrm = new JDialog(parentComp,title,true);
JLabel orLabel = new JLabel(msg);
CXUtil.updateFont(orLabel);
orLabel.setPreferredSize(new Dimension(200, 80));
orLabel.setHorizontalAlignment(SwingConstants.CENTER);
orLabel.setVerticalAlignment(SwingConstants.CENTER);
loadFrm.getContentPane().add(orLabel, BorderLayout.CENTER);
loadFrm.pack();
}
public void run() {
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
int dialogWidth = 250;
int dialogHeight = 100;
loadFrm.setSize(new Dimension(dialogWidth, dialogHeight));
// 设置等待画面位置
if(parentComp != null) {
Point ppoint = parentComp.getLocation();
Dimension pdim = parentComp.getSize();
ppoint.x = ppoint.x + pdim.width/2 - dialogWidth/2;
if(ppoint.x < 0) {
ppoint.x = ppoint.x + dialogWidth/2;
}
ppoint.y = ppoint.y + pdim.height/2 - dialogHeight/2;
if(ppoint.y < 0) {
ppoint.y = ppoint.y + dialogHeight/2;
}
loadFrm.setLocation(ppoint.x , ppoint.y);
} else {
loadFrm.setLocation(screenSize.width/2-dialogWidth/2, screenSize.height/2-dialogHeight/2);
}
loadFrm.setResizable(false);
loadFrm.setCursor(new Cursor(Cursor.WAIT_CURSOR));
loadFrm.show();
}
}
第二,Java中几乎所有的设施都是同步阻塞的.所以开线程是对的.
所以线程和notify你得熟悉一下.
第三,建议你写Java 程序的时候,写Console的测试程序,把功能写好了,再往UI里放,我一般是这么做的.
另外,你给的代码,似乎看不到问题的所在啊... ...
其他地方没有开thread了,需要全部的代码吗?
线程模型上面已经给出了.
代码比较多,贴出调用部分的框架:
// 按钮响应事件
private void insertCardInfo() {
try {
// 开了一个线程弹出等待画面
(new waitThread("增加", "增加处理中...",nodeMngFrame)).start();
cardInfo.setNodeName(nodeMngFrame.getNodeName());
cardInfo.setSlotNo(nodeMngFrame.getSelectNo());
cardInfo.setMibType(1);
cardInfo.setCardName(transValue(c_NameText.getText()));
cardInfo.setIp(transValue(ip_addressText.getText()));
cardInfo.setSubnet(transValue(subnetText.getText()));
cardInfo.setMac1(transValue(addColon(mac1Text.getText())));
cardInfo.setMac2(transValue(addColon(mac2Text.getText()))); cardInfo.setCardType(transValue(c_TypeComBox.getSelectedItem().toString()));
// 调用远程方法
result = nodeMngFrame.getCXNodeMngServer().addCard(cardInfo);
if (ErrId.SUCCESS == result) {
// 关闭等待画面
if(loadFrm != null) {
loadFrm.dispose();
}
} eles {
...............
} } catch (RemoteException e) {
// 连接失败
CXSnap.printStackTrace(e);
System.exit(1);
} catch (Exception e) {
CXSnap.printStackTrace(e);
System.exit(1);
} }
还是起了一个线程,在那个线程调RMI?