Java J2ME和LWUIT中的多线程

Java J2ME和LWUIT中的多线程,java,multithreading,java-me,lwuit,Java,Multithreading,Java Me,Lwuit,我想在从web服务加载一些数据时显示一个对话框 我用的是LWUIT 下面是代码 public class LoaderAnimation extends Container implements Runnable { private Thread t; private boolean running = false; public LoaderAnimation() { } public void start() { running = true; t = new Thre

我想在从web服务加载一些数据时显示一个对话框 我用的是LWUIT

下面是代码

public class LoaderAnimation extends Container implements Runnable {

private Thread t;
private boolean running = false;

public LoaderAnimation() {
}

public void start() {
    running = true;
    t = new Thread(this);
    t.start();
}

public void run() {
    while (running) {

            // do something
            t.sleep(150);
    }
}

public void stop() {
    running = false;
}
}
现在它运行了,但是调用web服务的代码停止工作了,会发生什么

这就是它的使命

public static void showLoaderScreen ()
    {
        dialog = new Dialog();
        dialog.setLayout(new BorderLayout());
        canvas = new LoaderAnimation();
        dialog.addComponent(BorderLayout.CENTER , canvas);
        canvas.start();
        dialog.show();
    }

public static void dismissLoaderScreen ()
{
    canvas.stop();
    dialog.dispose();
}

试试这段代码

private void startLoader() {
    Dialog d = new Dialog();
    d.getStyle().setBgColor(0xffffff);
    d.getStyle().setBgTransparency(255);
    d.show(100, 250, 90, 150, true, false);
    d.setAutoDispose(true);
    try {
        Thread.sleep(30);
    } catch (InterruptedException ex) {
        ex.printStackTrace();
    }
    d.dispose();
    new Timer().schedule(new TimerTask() {

        public void run() {

            new Loader().start();
        }
    }, 30);
}
我们可以编写解析内容或web服务处理等

 class Loader extends Thread 

{        public void run() {

            try {

                ServiceTypesScreen st = new ServiceTypesScreen();
                st.init();
            } catch (Exception e) {                    
                e.printStackTrace();
            }

        }
}

您发布的代码段是否编译?据我所知,抛出
InterruptedException
,但没有捕获-您当然不能重试,因为它是
可运行的
。另外,您最好将运行声明为
volatile