Java Reference
In-Depth Information
public
void
run()
{
Thread thd;
thd
=
Thread.currentThread();
String
name
= thd.getName();
Sys-
tem.out.println(name+" "+
tVal.get());
}
};
Thread thdChild = new Thread(rC);
thdChild.setName("Child");
thdChild.start();
}
};
new Thread(rP).start();
}
}
Afterinstantiating
InheritableThreadLocal
andassigningittoa
volatile
classfieldnamed
intVal
,thedefaultmainthreadcreatesaparentthread,whichstores
an
Integer
objectcontaining10in
intVal
.Theparentthreadcreatesachildthread,
which accesses
intVal
and retrieves its parent thread's
Integer
object.
When you run this application, you will observe the following output:
Child 10
BigDecimal
claredthisfieldtobeoftype
int
,andmentionedthat
balance
representsthenumber
ofdollarsthatcanbewithdrawn.Alternatively,Icouldhavestatedthat
balance
rep-
resents the number of pennies that can be withdrawn.