I am having a problem removing Steppables from the schedule dynamically. I
am stopping them in an extension of the Display2D class which I called
InteractiveDisplay2D where I can remove agents by clicking on the grid. But
I find even when stopping these Steppables that they will linger on the
schedule. For example, I am stopping them by means of:
schedule.scheduleOnce(schedule.getTime(), new Steppable() {
public void step(SimState state) {
// Stopping steppables in here
}
}
I read that if you do a schedule once on the current time that the steppable
will be put on the schedule at the current time plus epsilon. So I thought
this should work as I will have always stopped the Steppables after they
have executed and on the same thread. In that way, there should be no thread
interference. But still I am having this problem. This must have something
to do with the Display2D being on the event dispatch thread separate from
the thread the schedule is operating on. I cannot understand why though,
since I put the removal on the schedule itself.