import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import javax.imageio.ImageIO;
public class ImageIOTest {
public static void main(String[] args) throws Exception {
int nums = 800;
//for (int i = 0; i < nums; i++) {
// new Thread(new Tt1()).run(); //单线程
//}
new Thread(new DoMutil(30, nums)).run(); // 并发
Thread.sleep(1000000);
}
}
class DoMutil implements Runnable {
int threadNum = 1;
int nums = 1;
public DoMutil(int threadNum, int nums) {
this.threadNum = threadNum;
this.nums = nums;
}
@Override
public void run() {
ExecutorService executorService = Executors
.newFixedThreadPool(threadNum);
for (int i = 0; i < nums; i++) {
executorService.execute(new Tt1());
}
}
}
class Tt1 implements Runnable {
static String xx = "d:/x/xxx.png";
public void run() {
try {
BufferedImage image = ImageIO.read(new File(xx));
image.flush();
int width = image.getWidth();
Thread.sleep(100);
} catch (IOException e1) {
} catch (InterruptedException e) {
}
}
}运行条件:1.
放个图片在 d:/x/xxx.png 。我的图片大小为600多k。