public static void main(String[] args) throws InterunpedException{
    Thread t=Thread.currentThread();
    System.out.println("1");
    t.sleep(1000);    System.out.println("2");
    t.sleep(1000);           System.out.println("3");
}一运行就会跳出对话框,说 javaw.exe遇到问题需要关闭,不知道哪里有问题,大家帮帮忙啊

解决方案 »

  1.   

    程序只会打印1和2,我觉得应该在第二个sleep那里有问题,有谁遇到过么?
      

  2.   

    我这样改了一下,不知是否你要的结果:
    import java.io.InterruptedIOException;public class TestThread { public static void main(String[] args) throws InterruptedIOException, Exception{
    Thread t=Thread.currentThread();
    while(true){
    System.out.println("1");
    t.sleep(1000); System.out.println("2");
    t.sleep(1000); System.out.println("3");
    }
    }
    }
      

  3.   

    不好意思 刚才试了下,上面那个程序是可以运行的,我把我碰到问题的代码贴出来吧,大家帮忙分析下,分我会加的。
    public class TestAmzi {
    public void test() throws InterruptedException{


    Thread t=Thread.currentThread();

    Thread pc=new Thread(new PrologCompiler());
    pc.start();

    System.out.println(1);


    t.sleep(1000);



    System.out.println(2);
    Thread pl=new Thread(new PrologLinker());
    pl.start();

    t.sleep(1000); LogicServer ls=null;

    try {

    ls=new LogicServer();
    ls.Init("");
    ls.Load("test");
    long res=ls.CallStr("ura(user(lisi),role(g))");
    System.out.println(res);

    } catch(LSException e){
    e.printStackTrace();
    }finally{
    if(ls!=null){
    try{
    ls.Close();
    }catch(LSException e){
    e.printStackTrace();
    }
    }
    }
    }

    public static void main(String[] args) throws InterruptedException{
    TestAmzi ta=new TestAmzi();
    ta.test();



    }
    }PrologCompiler和PrologCompiler都是继承自Thread,只是运行了一个命令行程序而已。
    public class PrologCompiler extends Thread { public void run(){
    try {
    Runtime.getRuntime().exec("acmp test");
    } catch (IOException e) {
    e.printStackTrace();
    }


    }
    }上面程序打印1和2后就会跳出对话框,说 javaw.exe遇到问题需要关闭,不知道哪里有问题,大家帮帮忙啊
      

  4.   

    我只是想让pc和pl两个thread各自运行完(就是exec调用的命令行程序完成),再回到主程序里面继续向下执行
      

  5.   

    还是看下面这个吧,程序只能打印1,2,3,4,没打印5,要怎么改下呢,郁闷
    public class TestAmzi {
    public void test() throws InterruptedException,IOException{


    Thread t=Thread.currentThread();
    System.out.println(1);

    Runtime.getRuntime().exec("acmp test");

    System.out.println(2);
    t.sleep(1000);

    System.out.println(3);
    Runtime.getRuntime().exec("alnk test test");

    System.out.println(4);
    t.sleep(1000); System.out.println(5);
    LogicServer ls=null;

    try {
    ls=new LogicServer();
    ls.Init("");
    ls.Load("test");
    long res=ls.CallStr("ura(user(lisi),role(g))");
    System.out.println(res);

    } catch(LSException e){
    e.printStackTrace();
    }finally{
    if(ls!=null){
    try{
    ls.Close();
    }catch(LSException e){
    e.printStackTrace();
    }
    }
    }
    }

    public static void main(String[] args) throws InterruptedException,IOException{
    TestAmzi ta=new TestAmzi();
    ta.test();



    }
    }