Questions on concurrency and containers (get IllegalStateException)
in
Programming Questions
•
4 months ago
I am not really sure why I am getting this error (IllegalStateException).
I am using a pair of ArrayLists and iterating through them with some nested loops.
This list (where I get the exception) is populated in a keyPressed() routine.
In the draw() routine I am doing something as follows:
- ArrayList m,s;
- ...
- void draw(){
- //...
- Iterator<PVector> i,j;
- i = s.iterator();
- j = m.iterator();
- while (i.hasNext()){
- //...
- while (j.hasNext()){
- if ( /* some condition */) {
- i.remove();
- j.remove();
- }
- }
- }
- }
- void keyPressed() {
- if (key == ' ') s.add(new PVector(x,y));
- }
I am getting the exception on line 12. It could be happening at the same time as the keyPressed() if they are in fact in different threads.
1