e.printstacktrace () E IS AUSGABE
dann
Ich bekomme viel
java.lang.ILLEGALMONMONITORSPATEException aus Die Benachrichtigung funktioniert falsch, wie ich es richtig wecken sollte, bitte sagen Sie es mir, zeigen, richtig. Bitte < /p>
Code: Select all
import java.util.ArrayList;
import java.util.ArrayList;
public class Main extends Thread {
ArrayList threads;
public Main() {
super();
threads = new ArrayList();
}
public void run() {
for (int i = 0; i < 3; i++) {
threads.add(new Thread(new Task(i + 65)));
}
long cT = System.currentTimeMillis();
for (int i = 0; i < threads.size(); i++) {
threads.get(i).start();
}
while (System.currentTimeMillis() - cT < 10000) {
for (int i = 0; i < threads.size(); i++) {
try {
threads.get(i).notify();
// HOW TO WAKE THREAD FROM threads ArrayList
Thread.sleep(1000);
// how to put to bed the same thread ?
threads.get(i).wait();
} catch (Exception e) {
e.printStackTrace();
}
}
}
}
public static void main(String[] args) {
new Main().start();
//new Thread(new Task(65)).start();
}
}
< /code>
H < /p>
public class Task implements Runnable {
int nr;
char character;
public Task(int literaASCII) {
this.nr = 0;
character = (char) (literaASCII);
}
@Override
public void run() {
while (true) {
try {
System.out.print(nr + "" + character + ", ");
nr++;
int r = (int) ((Math.random() * 500) + 500); //