I want to write a game server using Mina. The server compute the new
state for each client and send message to each client every 40ms so
that every client can display a new frame.
some code followed:
------------------------------------------------------------------
private static Timer timer = new Timer();
//a mothed of Main class
public static void main(String[] args) {
//execute once every 40 ms to update the display of client
timer.scheduleAtFixedRate(new MatchTimerTask(), 0, 40);
}
public class MyTimerTask extends TimerTask {
public void run() {
//there is about several hundred sessions.
//do some business logic and send message to each client
for (int i = 0; i < sessionList.size(); i++) {
businessLogic();
//the session object is a instance of
org.apache.mina.common.IoSession
session.write(message);
}
}
}
//a mothed of ServerSessionHandler class
public void messageReceived(IoSession session, Object message) {
recordClientCommand(session, (CilentCommand)message);
}
------------------------------------------------------------------
May I use some better class instead of the Timer and the TimerTask class?
Where should I put the scheduled task code so that it may run in the
I/O processor thread?
thanks,
Yu X.W.