[英]Running Multiple Threads Freezing Java
I need to instantiate a class on a separate thread from my first one, I found this , which works, using it like this: 我需要在与第一个线程不同的线程上实例化一个类,我发现this可以正常工作,如下所示:
private class PongThread extends Thread {
public void run() {
new Pong(WINDOW);
}
}
And instantiating like this: 并像这样实例化:
new PongThread().start();
The problem is that if I try to instantiate it twice, then the program just stops responding. 问题是,如果我尝试实例化两次,则程序将停止响应。 So how do I do this so that I can make a new
PongThread
as many times as I want? 那么,我该如何做才能使一个新的
PongThread
尽可能多呢?
EDIT: 编辑:
My Pong class is a LWJGL Display running with a while loop and the sync(FPS)
method: 我的Pong类是使用while循环和
sync(FPS)
方法运行的LWJGL Display:
while(isRunning) {
//Logic and rendering method calls, etc.
Display.update();
Display.sync(30);
}
EDIT #2: 编辑#2:
My pong class contains and uses private classes (I don't know if that might affect it) 我的pong类包含并使用私有类(我不知道这是否会影响它)
Display class from LWJGL is a static class and I'm not sure if you can use it separately for different threads. LWJGL的显示类是静态类 ,我不确定是否可以将其分别用于不同的线程。 Try using JOGL instead.
尝试改用JOGL 。 It has more capabilities then LWJGL and it has much better support then LWJGL.
它具有比LWJGL更多的功能,并且比LWJGL具有更好的支持。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.