Saturday 17 October 2015

ThreadLocal in java

In real life we comes to a situation where we need a loged in user information or the Company Information in the implementation Classes. The way we are following is override the Implementation class in the HOOK.

In this we are passing the information into the parameter in the Method.

So many times we need to get the user information like username or company id .  In this case we will get themedisplay object from request and put information.

But Liferay has provided various thread local which will provide this information directly.
Following are some of the Examples

PrincipalThreadLocal : This thread local provide information regarding the Logged in User.
CompanyThreadLocal :  This thread local provides information about regarding company id.
LocaleThreadLocal : Provides locale of the current logged in user.