我正在尝试编写一个程序来解决囚犯和开关问题。我创建了一个 SwitchRoom 类..
public class SwitchRoom
{
private boolean switchA;
private boolean switchB;
和一个囚犯班
public class Prisoner
{
public void visitSwitchRoom() {
// do something with switches
现在我在想我该如何运行它。最好让 Prisoner 类实现 Runnable (将它们的实例变成线程)然后在 Java 程序中生成 23 个线程?
如果这是一个好方法,您能否提供一个代码示例让我开始?
如果这不是正确的方法,你能给我一些关于是什么的指示吗?