Thread only running correctly if there is a System.out.println() inside the while true loop

后端 未结 5 2047
礼貌的吻别
礼貌的吻别 2021-01-06 14:38

Basicly, I\'m making a game which to update the players position, it uses this thread:

@Override
public void run() {
    while(true) {
        System.out.pri         


        
5条回答
  •  慢半拍i
    慢半拍i (楼主)
    2021-01-06 15:28

    There is yet another appoach. You can use class java.util.Timer that is dedicated for implementation of scheduled tasks. It is very useful if for example you need now 2 threads that periodically perform some kind of different operations. Using Timer you can save your efforts and computer resources using only one thread

提交回复
热议问题