I am studying Thread but I don't fully understand yet. I got NullPointerException from the program below.
Please shed a light.
// Below is the program I ran.
}
Please shed a light.
// Below is the program I ran.
}
Rob Prime wrote:operator is still null because you never give it a value.
Rob Prime wrote:Well, that's because of the "while (true)". That means never stop. However, even if that loop would end the thread would not. That's because there will never be a notify(All) on that very same Operator instance.
Try the following:
This will print "Waiting", then waits 5 seconds, then will alternatively print out "No more" and "Waiting" until you press CTRL+Z to terminate the JVM.