Forums Register Login

Can't get notify() to work

+Pie Number of slices to send: Send
Basically the problem is that the last print statement "Code Block 4" does not print. This is because the main thread that calls notify() completes before the second thread (Thread-1) begins. As such when Thread-1 is called it permanently blocked as their is no active thread to call notify().

+Pie Number of slices to send: Send
This is because the main thread that calls notify() completes before the second thread (Thread-1) begins.

How true.

You need to communicate between the threads, back and forth. Read the tutorial and follow the instructions.
Concurrency
+Pie Number of slices to send: Send
See how this variation is different:

I narrowed the scope of the synchronized blocks so they only control the wait & notify. Work through what was synchronized in your version and see if that explains your results.
If you send is by car it's a shipment, but if by ship it's cargo. This tiny ad told me:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 781 times.
Similar Threads
Simple wait notify
Question about wait() method
invalidMonitorState
Lock Mechanism ?
synchronization and locks
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 29, 2024 05:51:43.