Variables you should care about

Threads can share the heap that includes class variables and instance variables. Each thread gets its own share of stack memory, which includes local variables, method parameters, and exception handler parameters. So a multithreaded application should safeguard the static and instance variables or attributes of its shared objects. Figure below shows the type of variables that are always safe in a multithreaded application. So it’s always the not-so-safe instance and static variables that you need to care about.

The terms static variables and static attributes, and instance variables and instance attributes, are the same and are often used interchangeably.

But what kind of operations should you care about? Should you only be concerned with the methods that change the value of a shared variable? Or, should you also synchronize the read operations? Let’s answer these questions in the next section.

Last updated