简体   繁体   English

为什么一个Java线程阻止在其他线程中完成的OpenGL渲染?

[英]Why one Java thread blocks OpenGL rendering that is done in other thread?

When I try to execute my Java code that uses Lightweight Java Game Library (LWJGL) in one thread, everything works fine. 当我尝试执行在一个线程中使用轻量级Java游戏库(LWJGL)的Java代码时,一切正常。 However when I start second Java thread that simply constantly prints text (see my text thread class pseudocode below) my OpenGL program becomes unresponsive, but the text is still printed. 但是,当我启动仅持续打印文本的第二个Java线程时(请参见下面的文本线程类伪代码),我的OpenGL程序将变得无响应,但文本仍会被打印。 No errors are shown. 没有显示错误。

 public class TextPrinterThread implements Runnable {
    public void run() {
        while(true) {
            System.out.println("My text");
        }
    }
}

I have read that OpenGL has problems with multithreading here and here and so on, however I do not try to separate OpenGL job in multiple threads. 我读过OpenGL 在这里这里等等都存在多线程问题,但是我不尝试在多个线程中分开OpenGL作业。 I use One thread solely for OpenGL and other thread to execute non OpenGL code. 我仅将一个线程用于OpenGL,而将另一个线程用于执行非OpenGL代码。 I did not find any suggestions on internet what is the cause of my problem, I tried changing thread priorities, but it did not help. 我没有在互联网上找到任何建议,这是导致我的问题的原因,我尝试更改线程优先级,但没有帮助。 Any help would be appreciated. 任何帮助,将不胜感激。

because this thread occupies CPU, 因为该线程占用了CPU,

verify: add sleep after print, see if main thread gets recovered. 验证:打印后添加睡眠,查看主线程是否恢复。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM