ThreadLocal in Java

preview_player
Показать описание
In Java multithreading there are two open requirements either safe data share or no share at all. Safe data share is achieved using multiple approaches but natively synchronized block is used to ensure that. Similarly ThreadLocal is to ensure that a variable is local to thread and is never touched by any other thread. Developers might think that isn't it same as declaring variable locally in thread. It's not as thread variable can still be accessed in multiple ways. Argument may rise like can't we make thread immutable and so on. Java community understood the issue and provided ThreadLocal. It maintains a thread map to persist thread specific data.

Thanks!
Рекомендации по теме
welcome to shbcf.ru