Politeness is an artificial good mood
In the Solution class, create a public static IntegerHolder class. IntegerHolder must accommodate an int (the variable name must be value), be thread safe, and be mutable. This class must have two public methods: get and set.
A wise man thinks once before speaking twice
All of the Solution class's methods except the main method must be thread safe. Make it so both methods can be executed simultaneously by two different threads. "synchronized(this)" isn't suitable here. Use another object for the lock.
Distributing items into baskets with their own lock
In the synchronized blocks, use the right lock.
GO TO FULL VERSION