I have a producer-consumer set of threads, but the producer is getting stuck on a line of code that isn't the .put()
, according to the JConsole stack trace.
class Producer implements Runnable {
private final BlockingQueue<CopyOnWriteArrayList<Creature>> queue;
private World myWorld;
Producer(BlockingQueue<CopyOnWriteArrayList<Creature>> q, World myWorld) {
queue = q;
this.myWorld = myWorld;
}
public void run() {
int nextTick = myWorld.myApp.getTick(); //'tick' is the current frame our main loop is on.
while (true) {
if (myWorld.myApp.getTick() >= nextTick) { //if our world has updated to the next frame…
nextTick = myWorld.myApp.getTick() + 1; //increment the next frame to wait for
try {
for (int i = 0; i < myWorld.getCellController()
.getColumns(); i++) {
for (int j = 0; j < myWorld.getCellController()
.getRows(); j++) {
queue.put(myWorld.getCellController().Cells.get(i)
.get(j));
}
}
} catch (InterruptedException ex) {
System.out.println("INT! ******************************");
} catch (NullPointerException ex) {
System.out.println("NULL! ******************************");
} catch (ClassCastException ex) {
System.out.println("CAST! ******************************");
} catch (IllegalArgumentException ex) {
System.out.println("ARG! ******************************");
}
}
}
}
}
According to the stack trace, it just stays on the while(true)
line, without advancing through the loop, even though it should.
Stack trace:
Name: Producer
State: RUNNABLE
Total blocked: 0 Total waited: 196,958
Stack trace:
concurrency.Producer.run(Setup.java:25)
java.lang.Thread.run(Thread.java:680)
Line 25 is the while(true) {
line.