Java multithreading - reader and writer thread in synchronized block -


this question job interview:

how identify read thread , write thread in synchronized block?

you can like:

thread current = thread.currentthread() 

and now; when have map/list/... of threads, can compare references. simple example:

you add 2 fields class:

private thread reader =  private thread writer =  

and do

synchronized foo() {   if (thread.currentthread() == reader) ... 

and record: although things easy, person dealing "this problem" should rather step back: smells xy problem on place.

meaning: in "real" world; consider code bad practice. likely, tries solve problem should solved in other ways!

so, answer interviewer better combination of direct technical answer; pointing out "bad practice" issue.


Comments

Popular posts from this blog

Command prompt result in label. Python 2.7 -

javascript - How do I use URL parameters to change link href on page? -

amazon web services - AWS Route53 Trying To Get Site To Resolve To www -