Avatar of Jay Roy
Jay RoyFlag for United States of America

asked on 

Threadlocal v/s Synchronization

hi guys

I was reading through Threadlocal v/s Synchronization and comtemplating which one to use.
Is threadlocal an alternative to synchronization  when it comes to scalability in high performance systems?
thanks
Java

Avatar of undefined
Last Comment
Mick Barry
ASKER CERTIFIED SOLUTION
Avatar of Mick Barry
Mick Barry
Flag of Australia image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
SOLUTION
Avatar of for_yan
for_yan
Flag of United States of America image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
Avatar of Jay Roy
Jay Roy
Flag of United States of America image

ASKER

can you guys post your knowledge in simple terms rather than pointing me to a link?

thanks.
Avatar of Mick Barry
Mick Barry
Flag of Australia image

I wouldn't think about it as an alternative for synchronisation. Instead think of it as another tool for dealing with threading issues. Understanding ThreadLocal and synchronisation will help you to determine which is the most appropriate in different scenarios.
For example if you have a huge objects that many threads are accessing then ThreadLocal may not be ideal as you are creating a new instance for each thread.
ThreadLocal is also not going to help you when your threads need to share data, thats more a job for synchonisation.
Avatar of Mick Barry
Mick Barry
Flag of Australia image

In general use ThreadLocal when you have multiple threads that each need their own copy of local data.
And synchronisation when multiple threads need to share some piece of data.
Java
Java

Java is a platform-independent, object-oriented programming language and run-time environment, designed to have as few implementation dependencies as possible such that developers can write one set of code across all platforms using libraries. Most devices will not run Java natively, and require a run-time component to be installed in order to execute a Java program.

102K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo