Weird issue with extension background tasks

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

Moderators: Lapo, Bax

noping
Posts: 4
Joined: 11 May 2020, 12:38

Weird issue with extension background tasks

Postby noping » 15 Sep 2020, 19:32

Hi,

So I have a working java extension. I had added a background "monitoring" thread to periodically check "state" and perform some actions.
It was working fine for a while and then stopped working. I don't think I changed anything with the code, so could have been an issue with the latest patch?

Code:

Code: Select all

@Instantiation(InstantiationMode.SINGLE_INSTANCE)
public class MyExtension extends BaseClientRequestHandler {

 private class TaskRunner implements Runnable {
        public TaskRunner(String rname) {
               ..
        }

        public void run() {
             trace("THIS CODE IS NEVER CALLED");
        }
 }
    public MyExtension () {
        SmartFoxServer sfs = SmartFoxServer.getInstance();
        taskHandle = sfs.getTaskScheduler().scheduleAtFixedRate(new TaskRunner(""), 0, 1, TimeUnit.SECONDS);
    }
   
    ...
 }

Any assistance would be greatly appreciated. Thanks
User avatar
Lapo
Site Admin
Posts: 21639
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: Weird issue with extension background tasks

Postby Lapo » 16 Sep 2020, 14:07

Hi,
the reason is that there is no exception trapping in the run() method of your task. In other words if a runtime exception is raised during the execution of the task the Task will be stopped.

Make sure to review the correct way to code a scheduled Task here:
https://smartfoxserver.com/blog/how-to- ... extension/

Cheers
Lapo
--
gotoAndPlay()
...addicted to flash games

Return to “SFS2X Questions”

Who is online

Users browsing this forum: No registered users and 20 guests