How to add syncronization properly Java
问题 As the integers are produced the Consumer thread sums their value (1+2+3…+10=55) Producer thread generates integers from 1 to 10 The program is meant to produce an integer and consume it right away. But, the result generated at the program’s end rarely equals 55. This is because the threads don’t wait for each other to complete their tasks Need to add syncronization to the code so that the consumer thread adds a value to the total only after a producer thread has generated a new integer