java线程 jni_哪位高手可帮小弟一个忙,十万火急!!!在java线程中可不可以调用JNI...

这篇文章探讨了一个Java线程在run()方法中通过JNI调用C++本地方法时遇到的问题,涉及线程阻塞。作者详细描述了问题现象,并提供了可能的原因分析和解决办法,重点在于并发编程中的资源管理和线程通信问题。
摘要由CSDN通过智能技术生成

在一个线程地run()方法中调用一个方法,该方法实例化一个包含本地方法调用的方法,可是该线程执行到该方法时就无反映了。

具体相关程序如下:

1。主程序

public class testJni

{

public static void main(String[] args)

throws java.io.IOException

{

Thread manager = new Thread(new testThread());

manager.setDaemon(true);

System.out.println("input 'exit' thread will stop.....");

manager.start();

}

}

2。线程

public class testThread

implements Runnable

{

public testThread()

{

}

public void run()

{

while(true)

{

long t = System.currentTimeMillis();

try

{

int intGetDecryptWPSFile = getDecryptWPSFile(args[0],args[1]);

}

catch(Exception e)

{

System.err.println("error is " + e.toString());

return;

}

try

{

Thread.sleep(1000);

}

catch(InterruptedException e)

{

}

}

}

private synchronized int getDecryptWPSFile(String strDocFileName,String strDecryptFileName)

{

int intTmp = -1;

DecryptWPSFile app = new DecryptWPSFile();

//decrypt是一个本地方法,由c++写成,编译为dll

intTmp = app.decrypt(strDocFileName,strDecryptFileName);

return intTmp;

}

}

3.调用本地方法的类

public class DecryptWPSFile {

static

{

//loadLibrary

System.loadLibrary("dll's name");

}

public native int decrypt(String str1, String str2);

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值