有一个start函数,里面有一堆线程,在main里调用这个函数什么问题都没有,现在加了一个button
用这段代码调用函数,一点按扭就奇慢无比,如同死机
Button bStart=new Button("开始获取");
bStart.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
System.out.println("ActionEvent" + e);
start();
}
});
add(bStart);
如果不调用start就什么事都没有,郁闷!
用这段代码调用函数,一点按扭就奇慢无比,如同死机
Button bStart=new Button("开始获取");
bStart.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
System.out.println("ActionEvent" + e);
start();
}
});
add(bStart);
如果不调用start就什么事都没有,郁闷!
主要看你在执行start()时都做了些什么
new Thread(){
public void run(){
// ...
// Your business codes
// ...
}
}.start();
}
我在run 里是这么写的
public void run(){
long i=0;
while (i<1000000000){
i++;}
System.out.println("ssss");
}
}.start();
在运行的时候界面还是死掉的。
private void start(){
new Thread(){
public void run(){
// ...
// Your business codes
try{
Thread.sleep(500);
}catch(Exception e){
}
long i=0;
while (i<1000000000){
i++;
}
System.out.println("ssss");
// ...
}
}.start();
}