since
shared data are simply declared globally.
As a pure object-oriented language,
Java has no such notion of global data.
If two or more threads are to share data in a Java program, the sharing occurs by passing references to the shared object to the appropriate threads.
In the Java program shown in Figure 4.12,
the main thread and the summation thread share the object instance of the Sum
class.
This shared object is referenced through the appropriate getSum() and setSum() methods. (You might wonder why we don’t use an Integer object rather than designing a new sum class. The reason is that the Integer class is
immutable—that is, once its value is set, it cannot change.)