本帖最后由 lgmsyy 于 2014-06-05 09:38:07 编辑

解决方案 »

  1.   

    1,先打出1111   2,OPEN SO动态链接库  3,初始化资源  4,打印2222  5,释放资源  6,打出3333   7, CLOSE so资源
    这个输出顺序是基于什么原理或依据呢?再看 在main方法中 和 在servlet 中 这个原理或依据 有没有变化,或者 上面代码执行的条件有哪些质变
      

  2.   


    普通JAVA和SERVLET调用的是同一个函数,并且是一模一样的。
      

  3.   

    代码说明
    普通JAVA代码
    public static void main(String[] args){

    Comp comp = new Comp();
    comp.lgm("a.bmp", "b.bmp");

    }
    servlet代码public void doPost(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException { try { 

    Comp comp = new Comp();
            comp.lgm("a.bmp", "b.bmp");


    }catch (Exception e){
    e.printStackTrace();
    }

    response.sendRedirect("/default.jsp");

    }
    被调函数public String lgm(String a,String b){
    String strScore = "zheng dao.";
    Comp hello = new Comp();
    hello.open(); String file1 = a;//args[0];//"a.bmp";//args[0];
    String file2 = b;//args[1];//"b.bmp";//args[1]; System.out.println("11111111111111111111111"); try{

    int init = hello.initTHFaceID("/gfserver/lib/Work",1);
    System.out.println("22222222222222222222222222"); int free = hello.freeTHFaceID(1);
    }catch(Exception e){ System.out.print("Pserrorerrorerrorerror:"+e.toString());
    e.printStackTrace();
    } System.out.println("333333333333333333333333333333");
    hello.close(); System.out.println("444444444444444444444444444444444");
    return strScore;
    }第三方厂商提供我们一个SO文件,里面有初始化资源函数,释放初始化资源函数,还有其他涉及业务的函数。。通过编写一个普通JAVA main程序可以调用成功。首先OPEN SO动态链接库,然后打出1111,然后又初始化资源,然后打印2222,然后打出3333,然后释放资源,然后CLOSE so资源,最后打出4444这样的顺序。但是我将同样的程序写在java servlet web工程下,为什么就执行就不对。
    1.首先顺序不对,先打出111没有错,然后分别打出22222,3333,然后才OPENT SO动态链接,然后初始化资源,然后释放资源,然后CLOSE SO资源(此时关闭错误),并且4444没有打印出来。难道是第三方提供的动态链接库不支持B/S结构的,或者是他们的SO中函数有另外的线程与JAVA SERVLET 线程不同步。仅仅开了一个SERVLE,就是说我是通过但线程执行的啊。
      

  4.   

    hello.close();    在servlet里面报错了  什么错误?
      

  5.   

    Comp 这个类是自己的还是别人的呢?能否把这个类给贴出来呢?
    还有就是 楼上讲的 hello.close 出错了,什么错误,将close方法和错误信息贴出来
      

  6.   


    public String lgm(String a,String b){       
        String strScore = "zheng dao.";       
        Comp hello = new Comp();
        hello.open();
     
        String file1 = a;//args[0];//"a.bmp";//args[0];
        String file2 = b;//args[1];//"b.bmp";//args[1];           
     
        System.out.println("11111111111111111111111");               
     
        try{       
             
            int init = hello.initTHFaceID("/gfserver/lib/Work",1);   
            System.out.println("22222222222222222222222222");           
     
            int free = hello.freeTHFaceID(1);
        }catch(Exception e){
     
            System.out.print("Pserrorerrorerrorerror:"+e.toString());
            e.printStackTrace();
        }                       
     
        System.out.println("333333333333333333333333333333");
     
     
        hello.close();   //close到这里就进行不下去了,4444没有打印出来。
     
        System.out.println("444444444444444444444444444444444");
     
     
        return strScore;
    }
      

  7.   


    public String lgm(String a,String b){       
        String strScore = "zheng dao.";       
        Comp hello = new Comp();
        hello.open();
     
        String file1 = a;//args[0];//"a.bmp";//args[0];
        String file2 = b;//args[1];//"b.bmp";//args[1];           
     
        System.out.println("11111111111111111111111");               
     
        try{       
             
            int init = hello.initTHFaceID("/gfserver/lib/Work",1);   
            System.out.println("22222222222222222222222222");           
     
            int free = hello.freeTHFaceID(1);
        }catch(Exception e){
     
            System.out.print("Pserrorerrorerrorerror:"+e.toString());
            e.printStackTrace();
        }                       
     
        System.out.println("333333333333333333333333333333");
     
     
        hello.close();   //close到这里就进行不下去了,4444没有打印出来。
     
        System.out.println("444444444444444444444444444444444");
     
     
        return strScore;
    }
    断点能不能打到Comp  这个类里面呢,能的话可以看看hello.close 都做了些什么,看什么原因导致执行不下去了
      

  8.   

    JNIEXPORT void JNICALL Java_com_Compare_open(JNIEnv *env, jobject obj){

    imglib = dlopen("libMidCompare.so", RTLD_LAZY);// RTLD_LAZY RTLD_NOW
    if(imglib!=NULL){
       printf("Open libMidCompare.so with handle ok.\n");
    }else{
       printf("Open libMidCompare.so with handle fail!\n");
    }

    }JNIEXPORT void JNICALL Java_com_Compare_close(JNIEnv *env, jobject obj){

    if (imglib != NULL ) {
    printf("close--2 ! \n");
        dlclose(imglib);
        printf("close--3 ! \n");//这个没有执行
          printf("Close with handle ok.\n");
    }else{
        printf("Close with handle fail!\n");
    }

    }
    public String lgm(String a,String b){       
        String strScore = "zheng dao.";       
        Comp hello = new Comp();
        hello.open();
     
        String file1 = a;//args[0];//"a.bmp";//args[0];
        String file2 = b;//args[1];//"b.bmp";//args[1];           
     
        System.out.println("11111111111111111111111");               
     
        try{       
             
            int init = hello.initTHFaceID("/gfserver/lib/Work",1);   
            System.out.println("22222222222222222222222222");           
     
            int free = hello.freeTHFaceID(1);
        }catch(Exception e){
     
            System.out.print("Pserrorerrorerrorerror:"+e.toString());
            e.printStackTrace();
        }                       
     
        System.out.println("333333333333333333333333333333");
     
     
        hello.close();   //close到这里就进行不下去了,4444没有打印出来。
     
        System.out.println("444444444444444444444444444444444");
     
     
        return strScore;
    }