Here is what is displayed when this program is run. It is probably not what was expected. Each
name should be enclosed within its own parentheses. The problem with the previous example is that
two threads use the same resource concurrently. The resource is the display() method defi ned in
the Parentheses class. In order to have one thread take control of the display() method, the
display() method must be synchronized. This is done by using the keyword synchronized in
the header of the display()method.
Now simply change the display method by writing synchronized keyword before void
synchronized void display(String ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month, and much more.