Login | Register   
LinkedIn
Google+
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


advertisement
 

Tip: Making a Java List Thread Safe

The java.util.list is not thread safe by default. Learn a quick workaround to make your list thread safe.


advertisement

WEBINAR: On-Demand

Unleash Your DevOps Strategy by Synchronizing Application and Database Changes REGISTER >

The java.util.list is not thread safe by default. There can be situations where you would want to use the list in a multithreaded environment for processing.

An effective mechanism is to use Collections.synchronizedList(ordinaryList) where ordinaryList is a normal list. The return value of this invocation is a thread safe list which can be used as desired.

// Creating a safeList that will be thread safe
List safeList = Collections.synchronizedList(ordinaryList);


 

Visit the DevX Tip Bank

 



   
Sridhar M S. is a Java developer from Bangalore, India. He holds a master's degree in Computer Science.
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap
Thanks for your registration, follow us on our social networks to keep up-to-date