public class Loader implements Runnable{
int players;
public static void main(String[] args){
Loader Loader = new Loader();
Loader.initiate();
}
public void initiate(){
Thread t1 = new Thread(new Loader());
t1.start();
while(true){
players++;
try {
Thread.sleep(5000);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
public void run() {
while(true){
System.out.println(players);
try {
Thread.sleep(5000);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
}
所以当我激活一个线程广播器来广播玩家数量时,我不能添加到玩家的 int 值并让它被广播......
玩家登录时玩家 = 0 --> 玩家++;但是当它广播的玩家数量仍然是0...