java - Is it possible to have a static variable unique per thread? -
i have static variable unique per thread.
is case static variables? or can not guaranteed. is, threads update static variable's value in main memory, or keep themselves?
if cannot guaranteed, there type of variable in java both static , thread-unique? global thread, hidden other threads?
i think looking java's threadlocal.
this class provides thread-local variables. these variables differ normal counterparts in each thread accesses 1 (via or set method) has own, independently initialized copy of variable.
mind you, if thread pooling may cause problems since may think getting new thread, in terms of starting new process, happening reusing thread finished working on other data , has left-overs , these hard debug when occur in wild.
here tutorial on using threadlocal.
Comments
Post a Comment