Hi,
I am facing this very strange problem with Smartfox 2x. I am scheduling a task using
sfs.getTaskScheduler().scheduleAtFixedRate(new TaskRunner(), 0, 1, TimeUnit.SECONDS);
in Zone level extension ( this code is called in init() function in the zone level extension)
but after sometimes when a user logs off , logs on or many different users log on , Scheduled task is getting stopped automatically without giving out any error. There is absolutely no error on the console just that the trace from the schedule task handler stops coming on the console.
We are using just one TaskScheduler for the entire zone , also task is scheduled to be executed always after one second. We have set the thread pool size for the schedulers pool to be 4.
In the scheduled task we are sending messages to the different room extensions by iterating over the rooms and then calling their extensions handleInternalMessage.
Also would like to highlight one thing that sometimes with 4-5 users logged in and with 20 different rooms , taskscheduler goes fine but sometimes even with one user if i log on , log off again and again the scheduler gets stopped.
The problem mentioned is very critical for us and delaying our product to go online in the beta stage.
We have been doing similar things earlier with smartfox 1x but didnt face any issue but on smartfox 2x the scheduler thread is getting stopped for no reason. We have now moved our development platform to smartfox 2x and we are stuck with this issue.
Please help !
Scheduled Task getting stopped automatically
Re: Scheduled Task getting stopped automatically
Hello.
Are you running the latest patch (2.1.0)?
And do you run any code at the USER_LOGIN or USER_DISCONNECT events?
Are you running the latest patch (2.1.0)?
And do you run any code at the USER_LOGIN or USER_DISCONNECT events?
Skills: SFS Pro, SFS2X, AS2.0/AS3.0, Java, HTML5/CSS3/JS, C#
Portfolio: https://rjgtav.wordpress.com/
SFS Tutorials: http://sfs-tutor.blogspot.com/ - Discontinued. Some examples may be bugged.
Portfolio: https://rjgtav.wordpress.com/
SFS Tutorials: http://sfs-tutor.blogspot.com/ - Discontinued. Some examples may be bugged.
Re: Scheduled Task getting stopped automatically
An exception can cause the task to stop.
Make sure to handle runtime exceptions in order to avoid the problem.
Make sure to handle runtime exceptions in order to avoid the problem.
Re: Scheduled Task getting stopped automatically
Siddhant wrote:Hi,
I am facing this very strange problem with Smartfox 2x. I am scheduling a task using
sfs.getTaskScheduler().scheduleAtFixedRate(new TaskRunner(), 0, 1, TimeUnit.SECONDS);
I prefer to use the one time scheduler instead of the scheduleFixedRate(). On your init() method, schedule one task and set to your target interval. Then on your TaskRunner(), surround your task with try/catch/finally block and then schedule your next task inside the finally block. This will ensure that a new task will be created even after an exception has occured. Something like this:
Code: Select all
private class TaskRunner implements Runnable {
public void run()
{
try{
// The code for your task
} catch(Exception e) {
} finally {
sfs.getTaskScheduler().schedule(new TaskRunner() 1, TimeUnit.SECONDS);
}
} // run()
}
"Dream it, I'll code it..."
Lead Developer
Optimal Solution Pte. Ltd.
Lead Developer
Optimal Solution Pte. Ltd.
Re: Scheduled Task getting stopped automatically
No I wouldn't recommend this approach. It has several disadvantages:
1- it keeps recreating objects
2- you can't keep state because the class gets recreated if there's an error.
Adds complexity instead of simplifying things. The mos rational approach is just to catch Exceptions so that the task doesn't get interrupted. And if you need to interrupt it on a specific error you can always handle the exception first, do your cleanup and finally re-throw your exception to stop it.
cheers
1- it keeps recreating objects
2- you can't keep state because the class gets recreated if there's an error.
Adds complexity instead of simplifying things. The mos rational approach is just to catch Exceptions so that the task doesn't get interrupted. And if you need to interrupt it on a specific error you can always handle the exception first, do your cleanup and finally re-throw your exception to stop it.
cheers
Re: Scheduled Task getting stopped automatically
@Lapo thanks a lot ..... we will execute our code in try catch block now .. i will update about the progress ....
Re: Scheduled Task getting stopped automatically
Lapo wrote:No I wouldn't recommend this approach. It has several disadvantages:
1- it keeps recreating objects
2- you can't keep state because the class gets recreated if there's an error.
Adds complexity instead of simplifying things. The mos rational approach is just to catch Exceptions so that the task doesn't get interrupted. And if you need to interrupt it on a specific error you can always handle the exception first, do your cleanup and finally re-throw your exception to stop it.
cheers
Hi Lapo, now I am confused . I actually used that approach as suggested on another post. Basically, on my implementation, I have attached one task scheduler to each room to periodically scan the game state and perform actions on it. I recreate the object like the above and recreate a new task scheduler after the task is completed successfully. if there is any error, the task will be aborted and no new task scheduler will be created. the reason why i am not doing the fixedrate scheduler is that the task involves database update and the task might run again while im still updating the database. before this approach, i have tried scanning all the rooms in a group using a task scheduler and then perform task based on the game state of each room. the problem is, if one game state requires database update, it will delay the scanning of the other rooms when i need to finish the scanning all the rooms in just 1 second.
since, i have learned now that this is a bad idea. what would be the best approach for this scenario?
"Dream it, I'll code it..."
Lead Developer
Optimal Solution Pte. Ltd.
Lead Developer
Optimal Solution Pte. Ltd.
Re: Scheduled Task getting stopped automatically
@foxboy: did I say it was a bad idea? I don't think so. I just said there's a simpler approach.
Rescheduling doesn't offer any advantage. If the thread is still working on the previous task the new task will have to either use a different thread or wait.
the task involves database update and the task might run again while im still updating the database.
Rescheduling doesn't offer any advantage. If the thread is still working on the previous task the new task will have to either use a different thread or wait.
Re: Scheduled Task getting stopped automatically
Thanks Lapo. I think I am gonna try your approach and see what happens.
"Dream it, I'll code it..."
Lead Developer
Optimal Solution Pte. Ltd.
Lead Developer
Optimal Solution Pte. Ltd.
-
- Posts: 1
- Joined: 12 Jul 2018, 05:09
Re: Scheduled Task getting stopped automatically
Hello
Why live smtartfox server is stop automatically.
Why live smtartfox server is stop automatically.
Re: Scheduled Task getting stopped automatically
Prahlad Yogi wrote:Hello
Why live smtartfox server is stop automatically.
Hi,
you should start a new thread, as this one is 6+ years old and it's not even relevant to what your problem seems to be.
Please start a new one and provide as many details as possible. If the server is stopped check the log files and look for errors, if there's any.
Thanks
Who is online
Users browsing this forum: Stevenor and 74 guests