I have Runnable
class:
package com.example.testtest;
public class FootballRunner implements Runnable {
@Override
public void run() {
while (true) {
System.out.println("Running " + Thread.currentThread().getId() + " " + Math.random());
try {
Thread.sleep(1_000);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
}
}
}
and have the main class:
package com.example.testtest;
public class TestScheduling {
public static void main(String[] args) throws InterruptedException {
FootballRunner footballRunner = new FootballRunner();
Thread t1 = new Thread(footballRunner, "one");
t1.start();
t1.wait();
}
}
but when I try to make it wait it throws an exception:
Exception in thread "main" java.lang.IllegalMonitorStateException: current thread is not owner
at java.base/java.lang.Object.wait(Native Method)
at java.base/java.lang.Object.wait(Object.java:338)
at com.example.testtest.TestScheduling.main(TestScheduling.java:8)
What does "current thread is not owner" mean? How I can make t1
to pause?