B4J Question Threads for a multiPlayer-multiRoom game

LucaMs

Expert
Licensed User
Longtime User
I would like to avoid bottlenecks in a b4j server for a multiplayer game.

I have read this Erel's statement:
In most cases it is a mistake to use the Threading library

I thought of creating a thread for each game room (instance of a class clsGameRoom).
All objects and rules inherent to a room in this class.

Objects of type clsPlayer containing references to WebSocketHandler objects (these also run in their own thread).

Vaguely, something like:
upload_2015-10-2_23-48-58.png


Is the above "method" right (and necessary) or can I avoid to use the Threading library?

Am I wrong or if I use a single module to handle all game rooms (in the Main thread) I would end up in that bottleneck?


Many thanks.
 
Last edited:

LucaMs

Expert
Licensed User
Longtime User
:mad::mad::mad:

Unfortunately, "probably" your smart solution can not be enough, @narek adonts .

The GameRoom class will have also private routines, to make calculations or other stuff.
These routines can not run in the Player thread.

Then I fear that GameRoom classes must run in their own thread (and I don't know the Threading library; I gave a quick look to it and it seems not so simple).
Is this right? (Please, answer: "No, it isn't" :p)
 
Last edited:
Upvote 0

LucaMs

Expert
Licensed User
Longtime User
I thought and I was hoping that I could run an entire class in a separate thread. In the Threading library example, some routines runs in different threads.

Maybe I can solve this way.

I could use Player thread when it is possible and run "private GameRoom routines" using the Threading library, calling them from the routines which currently run in Player thread.

But I'm not sure (also, if I could run an entire class in a separate thread it would be better), because, in the Threading library example, you declare a Thread in the Process_Globals and Initialize it in Activity_Create. The initialization seems to be also the start of the Thread. If I need to run a sub this way, I should have the possibility to re-initialize the same thread: is this feasible?


[Uhm... one thread for each routine? This is even worse.]

Yet a solution must exist.

PA%20-%20non%20rompere%20il%20PC.jpg
 
Upvote 0

LucaMs

Expert
Licensed User
Longtime User
I fear (again?) that I have to wait IF Anywhere Software will add another "special class" (b4j allows you to create different type of classes: server filter class, server handler class and server websocket class): server runnable class

https://developer.android.com/training/multiple-threads/define-runnable.html

but I need a solution now, indeed, I need a solution a few years ago :D:(
 
Last edited:
Upvote 0
Top