Page 1 of 1

Room extension sleep()

Posted: 18 Apr 2012, 14:27
by gofa
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.

Re: Room extension sleep()

Posted: 19 Apr 2012, 09:28
by Lapo
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

Re: Room extension sleep()

Posted: 19 Apr 2012, 12:20
by gofa
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

Re: Room extension sleep()

Posted: 19 Apr 2012, 14:01
by Lapo
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.