Room extension sleep()

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

Moderators: Lapo, Bax

gofa
Posts: 9
Joined: 20 Feb 2012, 13:50

Room extension sleep()

Postby gofa » 18 Apr 2012, 14:27

Inisde my room extension, i am using the sleep() function to cause a delay after the room filling up and before the game officialy starting

//last person joined
try{
//take 5
Thread.sleep(parent.GAME_START_PAUS_TIME_MILI);//if player exits now, ok game not started, they get back the cash
}catch(InterruptedException e){}
//start the game

I am just putting the delay hear in the room extension over in the server side, so that over on the client side I can play some animation ect, and the client has a change to they bail out if they want.

Is putting a room extension to Sleep a good idea ?, will this cause scailing proablems if we get loads of sleeping threads ?,

The aulternative is using the one zone level TaskSheduler, to start all unstarted games every 5 secs,
giving a delay of 0 to 5 secs depening when the room was created in time, in relation the the TaskSheduler interval period,
so not giving a constant delay.
User avatar
Lapo
Site Admin
Posts: 23025
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: Room extension sleep()

Postby Lapo » 19 Apr 2012, 09:28

No, it's a bad idea. You will lock the extension threads and degrade scalability.
What you should do is sending a delayed message to the players to start the game. This is done via the Scheduler: http://docs2x.smartfoxserver.com/Gettin ... wtos#item7

cheers
Lapo
--
gotoAndPlay()
...addicted to flash games
gofa
Posts: 9
Joined: 20 Feb 2012, 13:50

Re: Room extension sleep()

Postby gofa » 19 Apr 2012, 12:20

OK, Thanks, I changed my code to use the
getTaskScheduler().schedule(new StartTask());
and its works fine.

I see in the examples they are using the cancel() method, to stop the task,

In my code i am using the schedule() method to run the task after a delay one time,
so I dont need to call cancel() ? is that true ?

also, can you tell me what is going on with this TaskScheduler().

by calling: getTaskScheduler().schedule(new StartTask());
has a new Thred been created ?

or the taskScheduler thread pool is calling the method ?

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

Re: Room extension sleep()

Postby Lapo » 19 Apr 2012, 14:01

In my code i am using the schedule() method to run the task after a delay one time,
so I dont need to call cancel() ? is that true ?

Yes it is. You use cancel() only when you want to quit a task that is running "forever" (or before it completes the number of cycles you have specified)

by calling: getTaskScheduler().schedule(new StartTask());
has a new Thred been created ?

Nope. It will use one thread from the Scheduler's thread pool and return it as soon as it is finished.
Lapo

--

gotoAndPlay()

...addicted to flash games

Return to “SFS2X Questions”

Who is online

Users browsing this forum: No registered users and 53 guests