在一个线程地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);
}