I want to write a program that captures parts of my screen. In order to improve the number of pictures taken per second, I use 4 threads. My threads look like this:
class Sub1 extends Thread{
public void run(){
Rectangle screenRect1 = new Rectangle(0,0,89,864);
for(int i = 0; i<1000; i++) {
try {
Robot robot = new Robot();
BufferedImage screenLeft = robot.createScreenCapture(screenRect1);
} catch (AWTException ex) {
System.err.println(ex);
}
}
}
}
With different numbers for the rectangle object in each thread. I call this 4 times so i can get the most out of my i5 processor. However when i try to run it, the cpu usage is at about 30%. If I fill the threads with while(true){} I get 100% usage. Does this mean code cant be run parallel ? If so, what can I do to execute it parallel?