public class Main {
public static void main(String[] args) {
LinkedList<Th> myThreads = new LinkedList<>();
for (int i = 0; i < 100; i++) {
myThreads.add(new Th());
myThreads.get(i).start();
}
}
}
public class Th extends Thread {
int myInt;
@Override
public void run() {
while(true) {
doSomething();
}
}
private void doSomething() {
switch (myInt) {
case 0: {
// System.out.println("comment part");
break;
}
case 2:{
System.out.println("2");
break;
}
}
}
}
Hi, I have trouble with a simple multithreading in java. when I run this program, cpu usage is suddenly 100% and my computer crashes and I can't stop the program. Here you can see the code. when I un-comment the comment part, everything is ok! but I need to fix this without printing anything in the console. PS. I already know that case 2 codeblock is never compiled.