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

后端 未结 5 2050
礼貌的吻别
礼貌的吻别 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条回答
  •  忘掉有多难
    2021-01-06 15:08

    A Thread.yield() can also do it in some cases. See https://www.javamex.com/tutorials/threads/yield.shtml for example. The author of this link does not recommend to use yield however.

提交回复
热议问题