Why is my ScheduledTask stopping when User Disconnects?

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

Moderators: Lapo, Bax

JuliusBtesh
Posts: 58
Joined: 30 Sep 2014, 17:08

Why is my ScheduledTask stopping when User Disconnects?

Postby JuliusBtesh » 05 Dec 2014, 17:35

My serverside (java) scheduledTask seems to be interrupted when a User gets Disconnected from the game room

Code: Select all

npcRunnerTask = SmartFoxServer.getInstance().getTaskScheduler().scheduleAtFixedRate
      (
                       
         npcRunner,          
         0,                      // 0 initial delay
         100,                   // run every 100ms
         TimeUnit.MILLISECONDS      
      );


That was from the mmo demo room stuff that Im still using in my script. Nothing seems to be calling a stop or cancel for this task so I find it very odd that as soon as the user gets disconnected, the Runnable task stops running.

This needs to be handled asap, thank you!
User avatar
Lapo
Site Admin
Posts: 23008
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: Why is my ScheduledTask stopping when User Disconnects?

Postby Lapo » 09 Dec 2014, 10:14

Hi,
any scheduled task will be stopped if you don't handle Exceptions yourself. That's the only condition in which it can be stopped outside of your control.

Make sure in your run() method you enclose all of your code with a try { ... } catch (Exception e) { ... } block so that you can capture any error and deal with it. I don't think the disconnection is directly involved in the problem but maybe, after it happens, one of your calls generates an exception which in turn causes the task to stop.

Hope it helps
Lapo
--
gotoAndPlay()
...addicted to flash games
JuliusBtesh
Posts: 58
Joined: 30 Sep 2014, 17:08

Re: Why is my ScheduledTask stopping when User Disconnects?

Postby JuliusBtesh » 09 Dec 2014, 12:22

I will try putting the try/catch in this runnable task , I think I tried before and didnt catch anything.
It's weird because I have another scheduledtask that still continues its calls (But this one is not updated every second, this one gets called after a certain amount of time).
Nothing gets called once the User gets disconnected, which is exactly what I want. I just want the game to continue as is. I look at the logging in the SFS2X output and I see that it says that the user gets disconnected (which is expected) and then after a few more outputs of my runnable task, it just stops completely.
JuliusBtesh
Posts: 58
Joined: 30 Sep 2014, 17:08

Re: Why is my ScheduledTask stopping when User Disconnects?

Postby JuliusBtesh » 09 Dec 2014, 12:36

Ok thank you very much! I was able to catch the problem. Very dumb mistake that I overlooked! Thank you once again

Return to “SFS2X Questions”

Who is online

Users browsing this forum: No registered users and 64 guests