Prev Next

Java / Java ThreadLocal

Generic ThreadLocal variables.

ThreadLocal is a generic class which helps eliminates the need of typecasting the value being returned by the get() method.

The below code shows the way to create a generic ThreadLocal variable.

private ThreadLocal<String> thrLocalVarValue = new ThreadLocal<String>();

Creating a generic ThreadLocal variable ensures type safety thus set() method accepts only String and get() method returns only String Object eliminating the need of manual typecasting.

❤Cash Back At Stores you Love !!!❤

Earn your $10 reward when you make your first purchase through Ebates by signing up with clicking below button.

Ebates Coupons and Cash Back

More Related questions...

Show more question and Answers...

Java Multithreading

Comments & Discussions