I am trying to spread a time-taking loop over many threads, and I get a NullPointerException
for some reason. I checked if the thread_array
was empty, but it wasn't. Any suggestions at what I am doing wrong? Here is my code:
Inner Thread Class
class RowAndThetaThread implements Runnable{
private int x_0;
private int y_0;
public void run() {
// do something
thread_semaphore.release();
}
public void input_elements(int x, int y) {
x_0 = x;
y_0 = y;
try {
thread_semaphore.acquire();
} catch (Exception e) {}
this.run();
}
public void lol() {
System.out.println("LOLOLOLOL");
}
}
Thread Calling
RowAndThetaThread[] thread_arr = new RowAndThetaThread[LENGTH];
thread_semaphore = new Semaphore(thread_arr.length, false);
for (int i=0; i<border_que.arr.length; i++) {
thread_arr[i].lol(); // NullPointerException happens here
}