Currently, we have an SFS 2.13.7 Version server in our system, and we are created more than 30 rooms (timer games) each room has a separate Scheduler task and keeps running with a one-sec delay. More than 100 players joined in the single room and place their bets, when the timer ended as '0' (Zero sec), we started each Scheduler task for a single player. fox example 100 players - 100 Scheduler tasks. Sometimes, the Scheduler task takes a 5 - 10 sec delay to execute the task. Can you give suggestions?
Code:
Code: Select all
Room Thread
-----------
ScheduledFuture<?> gameThread;
gameThread = SmartFoxServer.getInstance().getTaskScheduler().scheduleAtFixedRate(new gameRunner(), 0,1, TimeUnit.SECONDS);
private class gameRunner implements Runnable {
public void run() {
try {
switch(state) {
case INITATEGAME : initateGame(); break;
case START_PLAY : startPlay(); break;
case WAIT_FOR_NEXT_GAME : nextRoundAction(); break;
case STOP_THREAD : stopThread(); break;
default: break;
}
} catch (Exception e) {
logger.error("Room :: " + getParentRoom() + " Error :: " ,e);
}
}
}
private void initateGame() {
// Code Development
-- Change the state to START_PLAY
}
private void startPlay(){
// call the player Thread here
- Chante to state to WAIT_FOR_NEXT_GAME
}
private void startPlay(){
- Chante to state to INITATEGAME
}
Note : suppose any issue in the above method, it will call the STOP_THREAD state
private void stopThread() {
if(gameThread!=null){
gameThread.cancel(true);
}
}
Player Thread
-------------
SmartFoxServer.getInstance().getTaskScheduler().schedule(new PlayerGameRunner(user), 0,TimeUnit.MICROSECONDS);
private class PlayerGameRunner implements Runnable {
private User user1;
ic PlayerGameRunner( User user) {
this.user1 = user;
}
@Override
public void run() {
try {
handleProcess(user1);
} catch (Exception e) {
logger.error("Room :: " + getParentRoom() + " Error :: " ,e);
}
}
private void handleProcess(User user){
Insert db records ( External db)
Buy In service call (External Call)
}
}
Note : Please find the Thread pool Configuration