Multithreding problem

I’ve just finished with basics and want to go further within game logic. There is a wiki doc about multithreading, but there is no info I need. Are there any special classes to use multithreading?

For example, I want to write AI bot class that has to do something by certain logic and other class for a player who is using keyboard/mouse inputs.

You can just use the java concurrency classes, when you modify jME objects from another thread, do it like this:

[snippet id=“10”]



Thanks for reply.

Could you explain widely, where I should use it?

No, that depends on what you want to do, loading models before adding them to the scenegraph would be one example. If you have no idea what mutithreading does or means apart from “using more than one cpu” you should probably research/learn a bit more before you try to apply multithreading to your application.



Oh, I’m sorry. I have to correct my question. How should I use it, where in code (may be in simpleUpdate())? This is not my first game I’m writing (they were 2D), and I know things about deadlocks and lockers.

My previous games had one thread ClockPulse, the others were to draw and make actions and followed to the ClockPulse. In loop the first tick() makes action, the second draws in screen.

I wanted to do the same here, but simpleUpdate method has time value. How should I follow this time, if I shouldn’t, is there any other way?

I can still give you no other answer. You could create some Callables for your own Executor in an update() call and then check in the subsequent update() calls if your processes have finished and then apply your changes for example… I think you still have only a sketchy idea of multithreading, read for example the first paragraph here about applying multithreading in an application… jME internally uses or will use multithreading where appropriate (for example for terrain mipmapping, audio, parts of the animation subsystem).

Hope this helps,


Would you recommend using Callable? I have done it it with conditions and signals/awaits and it works good for me.

Yes the idea behind callabls is that the work can be done while the game continues, it only has to stop if you need a future (google if you don’t know what a Future is)