通过for循环需启动3个线程。结果只有两个有结果。(结果不正确时,Thread.sleep(5000)无效)
public static void main(String[] args) throws Exception {
for (int i=0 ;i<3;i++){
new TestJNIThread().start();
}
Thread.sleep(50000);
}
public class TestJNIThread extends Thread {
@Override
public void run() {
//通过JNI调用dll文件执行图片裁剪
byte[] b1 =TestMethod.image2Bytes("E:\\img\\test.png");
long begin = System.currentTimeMillis();
int resultKey = JniMethod.image_crop_0(b1,3,10,4,3);
byte[] resultImgeByte = leaiapidep.get_data_0(resultKey);
long time = System.currentTimeMillis()-begin;
System.out.println(time);
}
}
以上代码,当我多次点击RUN运行后,会打印出:
15
15
(当打印结果不正确时,main方法中的Thread.sleep(50000)没有生效)
明明for运行i=0;i<3 为什么有时候会只有2个呢?
在run最开始输出一个信息,才能确定线程数。因为在最后才输出,有可能run执行中间发生 异常,后面就不会再输出。