[concurrency-interest] RE: Synchronization of data read by multiplethreads

Dawid Kurzyniec dawidk at mathcs.emory.edu
Sat Oct 29 13:19:04 EDT 2005


Ryan LeCompte wrote:

>
> Hello all,
>
>
>
> As a follow-on to my original question… I have another scenario where 
> I’m not entirely sure if synchronization/volatile is needed. Let’s say 
> we have the following:
>
>
>
> Class Test implements Runnable {
>
> Private boolean instantiated = false;
>
>
>
> Public Test() {
>
> Instantiated = true;
>
> }
>
>
>
> private boolean isInstantiated() {
>
> Return instantiated;
>
> }
>
>
>
> Public void run() {
>
> If (isInstantiated()) {
>
> // do something
>
> }
>
> }
>
> }
>
Just a question: why do you need the "instantiated" field in the first 
place? Do you ever set it to false? If not, it can be made final, and 
consequently, removed completely. If yes, you probably set it from 
another thread, so you may need synchronization after all.

Regards,
Dawid





More information about the Concurrency-interest mailing list