public class Nmstestsendfsk {
// TODO 自动生成方法存根 /**
 * @param args
 */
public static void main(String[] args) {
 Thread n1=new testthread (64,1);
 Thread n2=new testthread (64,2);
 Thread n3=new testthread (64,3);
 n1.start();
 n2.start();
 n3.start();
}}
class testthread extends Thread {
int st;
int sl;
JCtaNmsApi nms; public testthread (int stream, int slot) {
this.sl = slot;
this.st = stream;
this.nms = new JCtaNmsApi();
} public void run() {
            nms.init(stream, slot);
            nms.startpro();
            nms.extends();
}}
//jni 接口,具体实现由C实现,生成一个testdll.dll
public class JCtaNmsApi {
static {
try {
System.loadLibrary("testdll");
} catch (UnsatisfiedLinkError x) {
System.out.println("jninmss Libray Error");
}
}
public native boolean init(int stream, int slot);
        public native boolean startpro();
        public native boolean extends();
        
}各位达人给指导下,我运行就报java虚拟机的错.

解决方案 »

  1.   

    位达人给指导下,我运行就报java虚拟机的错.
    我没看到错误在哪里,属于【神仙问题】
      

  2.   

    你把Thread n1=new testthread (64,1); 
     Thread n2=new testthread (64,2); 
     Thread n3=new testthread (64,3); 
     n1.start(); 
     n2.start(); 
     n3.start(); 
    改为 testthread n1 = new testthread(64, 1);
    testthread n2 = new testthread(64, 2);
    testthread n3 = new testthread(64, 3);
    n1.start();
    n2.start();
    n3.start();就不会报报java虚拟机的错了.
    通过继承Thread类来实现多线程的时候,不应该直接用Thread类创建新对象.
      

  3.   

    testthread n1 = new testthread(64, 1); 
      

  4.   

    LZ我试过了,可以了.
    楼主真是强啊,字段Java无法直接访问到操作系统底层(如系统硬件等),竟然能够想到使用native方法来扩展Java程序的功能。 达到运行效率上的提高!!!
      

  5.   

    顺便问一句, 通过继承Thread类来实现多线程的时候,不应该直接用Thread类创建新对… 这个规则是哪里看到的??
      

  6.   

    用了testthread n1 = new testthread(64, 1); 
    testthread n2 = new testthread(64, 2); 
    testthread n3 = new testthread(64, 3); 还是不行,报这个错误,刚才上网搜了下,好像是说jni的env不能支持多线程访问,不知道有没有方法解决。
    都快疯了,老大让后天出结果,现在卡在这,不知道怎么往下走了
    #
    # An unexpected error has been detected by HotSpot Virtual Machine:
    #
    #  EXCEPTION_ACCESS_VIOLATION (0xc0000005) at pc=0x02db1a38, pid=6064, tid=5964
    #
    # Java VM: Java HotSpot(TM) Client VM (1.5.0_06-b05 mixed mode, sharing)
    # Problematic frame:
    # C  [CTA.dll+0x1a38]
    #
    [thread 5844 also had an error]
    # An error report file with more information is saved as [thread 5844 also had an error]
    [thread 6128 also had an error]
    #
    # If you would like to submit a bug report, please visit:
    #   http://java.sun.com/webapps/bugreport/crash.jsp
    #