#Run block of codes inside a scheduler twice

1 messages · Page 1 of 1 (latest)

median lotus
#

I use smart fox server. There are two servers on tcp port 9955 and 9956

final Timer timer = new Timer(); timer.scheduleAtFixedRate(new TimerTask() { @Override public void run() { try { appUtils = new AppUtils(ext); conn = ext.getParentZone().getDBManager().getConnection();

 
                    nextUpdateTime += resetLeaderboardPeriod * DAY;
                    Statics.nextVipLeaderBoardUpdate = nextUpdateTime;

                    int tcpPort = BitSwarmEngine.getInstance().getSocketAcceptor()
                    .getBoundSockets().get(0).getPort();

                    if (tcpPort == 9955) {
                        //here twice
                    }

                } catch (Exception e) {
                    //...
                } finally {
                    //...
                }


The problem is that the block inside if block is called twice. We have two servers one on 9955 and the other on 9956. What is the problem? race condition? thread unsafe?

trim furnaceBOT
#

<@&987246399047479336> please have a look, thanks.

median lotus
willow zealot
median lotus
willow zealot
#

then why are you using a Timer ?

#

instead of an executor ?

median lotus
#

I want to run a routine at fixed rate but just once for the server on port 9955 and not on 9956

#

Could you please explain more? what is the benefit?

#

Should I use executor?

willow zealot
median lotus
#
if (tcpPort == 9955) {
                        //here twice
                    }
trim furnaceBOT
median lotus
#

Here, it is called twice. Inside if block

willow zealot
#

check outside of the method the value of tcpPort

median lotus
#

OK, thanks

#

Is the code above thread unsafe?

willow zealot
#

depends of the context

median lotus
#

Can it be the reason?