I read in one of the articles that to break the task, just throw an exception.
I tried throwing an exception within run() in the case of an error but the scheduled task still runs.
How can I kill the scheduled task from within the task itself?
SFS scheduled task
Re: SFS scheduled task
Hi,
can you show me the code of your task?
Thanks
can you show me the code of your task?
Thanks
Re: SFS scheduled task
It gets inside the exception condition, but it doesn't kill it.
This is called from another class
MMOGame.getInstance().SFS().getTaskScheduler().scheduleAtFixedRate (
new PlayerMonitorTask(GetNetworkId (), GetId()), 0, PLAYER_MONITOR_TASK_INTERVAL, TimeUnit.MILLISECONDS);
This is called from another class
MMOGame.getInstance().SFS().getTaskScheduler().scheduleAtFixedRate (
new PlayerMonitorTask(GetNetworkId (), GetId()), 0, PLAYER_MONITOR_TASK_INTERVAL, TimeUnit.MILLISECONDS);
Code: Select all
package pixelmmo.model.task;
import com.smartfoxserver.v2.entities.User;
import pixelmmo.logging.MMOLogging;
import pixelmmo.model.MMOPlayer;
import pixelmmo.model.MMOWorld;
import pixelmmo.server.MMOGame;
public class PlayerMonitorTask implements Runnable {
private int _id;
private int _pcid;
public PlayerMonitorTask (int id, int pcid) {
_id = id;
_pcid = pcid;
}
@Override
public void run () {
User user = MMOGame.getInstance().Ext().getParentRoom().getUserById(_id);
if (user == null || !user.isConnected()) {
MMOLogging.LogError("user not found " + _id + " " + _pcid);
MMOPlayer pc = (MMOPlayer) MMOWorld.getInstance().FindObject(_pcid);
if (pc == null) {
MMOLogging.LogError("PC is not found too id: " + _id + " pid:" + _pcid);
try {
throw new Exception ();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
} else {
pc.StopMonitors ();
//pc.Logout();
}
return;
} else {
//MMOGame.getInstance().Log("user monitor");
}
((MMOPlayer)user.getProperty("MMOPlayer")).Update();
}
}
Re: SFS scheduled task
The problem is that you're throwing an exception and catching it at the same time
This is not how it works, you need to throw an (unchecked) exception so that the execution leaves the run() method.
In other word just use:
Cheers
This is not how it works, you need to throw an (unchecked) exception so that the execution leaves the run() method.
In other word just use:
Code: Select all
throw new RuntimeException();
Cheers
Re: SFS scheduled task
RuntimeException fixed it!
I couldn't throw Exception without try/catch without the ide erroring out.
I couldn't throw Exception without try/catch without the ide erroring out.
Who is online
Users browsing this forum: No registered users and 140 guests