jMonkeyEngine uses a swing-style threading model where there is a single render thread that does all the work. Any changes to the scene graph have to be done from that render thread.
To get into the render thread you can implement AppStates
, Controls
or you can enqueue
Callable
s which are then executed on the render thread in a similar way to Swing's invokeLater
.
The code snippet you posted looks about right, so assuming m is your running jME3 SimpleApplication then m.enqueue() will cause the enqueued callable to be executed next time around the render loop (i.e. at the start of the next frame).
If you are not seeing it executed then either:
- Your application is not running
- You created more than one application and enqueued it to the wrong one
- The code is actually running and you just think it isn't.
Stepping through the code in the debugger and/or adding debug statements (for example breakpoint inside removeContainersFromMaritime
to see if it is actually called should allow you to narrow this down.