Which games use multi threads in Java?

Hello everyone, so i will be doing a Java project for my Advanced OOP class and one of the requirements is that we need to use multi threads. And it will be the first time i will be using multi threads, so i was wondering if anyone has some examples where that is used? More specific, how is used in games?

Thanks in advance. :)

2 Likes

Minecraft. The game isn't perfectly multithreaded (everything that runs on "ticks" only runs on a single core), but it does use multiple threads (in my personal experience, 2-3 on a quad-core CPU).

1 Like

Concurrency is one of those things that has no easy solution for a given problem. You just have to learn the formal forms and then try your best to apply the right techniques to find a solution for your problem. With that in mind, it is typical to have all game world events broken into components. Best case scenario you can then decouple the different behaviours of your game world objects such as rendering or applying physics. Once broken into components, you can update the scene while rendering it concurrently. Actually achieving this requires strategies for data access and serialisation of some operations.

If you want to do this well; when updating on a frame, tick, or timed event, you should also inform the update function for a game world object of how long it has been since the last tick. It is fairly common in game thread loops to keep track of when loop iterations occur and propagate this information to each object being updated. This allows the object being updated to scale its actions based on that timing. See also: Unity Engine.

Remember that concurrency has an overhead, so fine-grained concurrency has to be done very carefully. In my experience, the only effective fine-grained concurrency has to be implemented as an optimisation only when it suits the problem it is solving very well. For an example; vector/matrix operations can be highly optimised. SIMD is also a good idea, but probably not what you are expected to implement.

Don't look exclusively for Java based tutorials. Game programming is not mostly done in Java, so you'll limit your ability to find information on concurrency strategies. For instance here is a C++ based worked through example for a component based approach: http://gameprogrammingpatterns.com/component.html

There are other solutions to the problem of concurrency in games (See: functional programming & agent-based models). For a functional approach, it is typical achieve a concurrent rendering thread by having an immutable rendering copy of the scene (or rendering properties of each object in the scene) while operating on a working set. The rendering copy can then be updated atomically, or created on each render. This copy, or another copy, or componentised copies, can also be used for a game logic thread to operate from when creating the working set.