Hi,
in my previous game with SFS 1.6 I used an executor service that handled additional threads to perform actions that connect to our database. This also includes the login process. In SFS2X however it seems that I can not invoke an additional thread to complete the login process, because the Login handler will trigger the login as soon as the event handler returns. So is there any other way to achieve a multithreaded login process or will I have to stay in the same thread?
Thanks in advance
edit: We are actually using a php backend that validates the users so the login process may take some time that is best spent in a second thread to not block the ingame actions.
custom login and multithreading
Hi,
interesting question. This is a bit advanced and I am sorry if we haven't touched on this yet in our documentation. The next articles we will publish will include these topics too.
in SFS2X events are fired by one entity only called (predictably) EventManager. The EventManager is backed by a Thread pool that can be resized at runtime. This should be enough for almost all needs as regards adding threads for long running activities.
All you need to do is configure the manager's thread pool so that it uses enough threads for your needs. This means that any other slow operation executed by your code in any other event handler will also benefit from the new settings.
In the init() method of your Extenion's main class you just need this line:
where xy is the number of threads you want.
NOTE: Just pay attention not to include this line in multiple extensions or each one will reconfigure the manager but only the last one will have effect.
interesting question. This is a bit advanced and I am sorry if we haven't touched on this yet in our documentation. The next articles we will publish will include these topics too.
in SFS2X events are fired by one entity only called (predictably) EventManager. The EventManager is backed by a Thread pool that can be resized at runtime. This should be enough for almost all needs as regards adding threads for long running activities.
All you need to do is configure the manager's thread pool so that it uses enough threads for your needs. This means that any other slow operation executed by your code in any other event handler will also benefit from the new settings.
In the init() method of your Extenion's main class you just need this line:
Code: Select all
public void init()
{
SmartFoxServer.getInstance().getEventManager().setThreadPoolSize(xy);
}NOTE: Just pay attention not to include this line in multiple extensions or each one will reconfigure the manager but only the last one will have effect.