|
How can this control synchronization?
When there is nothing at first, two kinds (8) of get threads are blocked, and two kinds (8) of put threads compete. Assuming that one of the putApple wins, it will put 1 apple and wake up the other threads to continue the competition. If a getOrange wins at this time, it will be executed from the wait block, so the program will take an orange. . . Obvious logical errors.
Method:
Define two lists (array or Integer is also possible) on the plate, one orange and one apple, and use these two things to control the two pairs of get / put methods respectively. |
|