Questions regarding Multithreading

Post here your questions about SFS2X. Here we discuss all server-side matters. For client API questions see the dedicated forums.

Moderators: Lapo, Bax

Ardito
Posts: 128
Joined: 12 Sep 2016, 11:26
Location: Italy

Questions regarding Multithreading

Postby Ardito » 05 Apr 2022, 11:15

Hi,
I have some questions regarding Multithreading:

I have some code like this:

Code: Select all

public class ScriptHandler extends BaseClientRequestHandler
{
   @Override
   public void handleClientRequest(User user, ISFSObject params)
   {
   String test = params.getUtfString("test");
   ...
   ...
   (Many, many, many instructions)
   }
}

or

Code: Select all

public class ScriptHandler extends BaseServerEventHandler
{
   @Override
   public void handleServerEvent(ISFSEvent event) throws SFSException
   {
   User user = (User) event.getParameter(SFSEventParam.USER);
   ...
   ...
   (Many, many, many instructions)
   }
}

If multiple requests arrive at the same time, how does SmartFox manage them?

Are the variables assigned at the beginning of the code overwritten even if the Tread has not finished all the instructions?
Or wait for the Tread to finish the instructions before overwriting the initial variables?

Greetings
User avatar
Lapo
Site Admin
Posts: 23027
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: Questions regarding Multithreading

Postby Lapo » 05 Apr 2022, 12:19

Hi,
If multiple requests arrive at the same time, how does SmartFox manage them?

They are handled by a different thread.

Are the variables assigned at the beginning of the code overwritten even if the Tread has not finished all the instructions?

No. Every thread has its own stack where local variables are created. So there's no chance of overwriting anything.

Or wait for the Tread to finish the instructions before overwriting the initial variables?

They always run in parallel unless you add locking instructions that modify the normal execution.

Cheers
Lapo
--
gotoAndPlay()
...addicted to flash games
Ardito
Posts: 128
Joined: 12 Sep 2016, 11:26
Location: Italy

Re: Questions regarding Multithreading

Postby Ardito » 05 Apr 2022, 21:59

Thanks, you have clarified all my doubts !!

Return to “SFS2X Questions”

Who is online

Users browsing this forum: No registered users and 116 guests