PrivilegedCarbonContext is a special subclass of
CarbonContext, which allows you to perform privileged operations such as, setting the tenant ID and domain, starting or ending tenant flows and more. This class can only be used by Carbon components that have the permission to get hold of an instance of the
PrivilegedCarbonContext. An instance of
PrivilegedCarbonContext can only be obtained using the static methods outlined in Obtaining the PrivilegedCarbonContextbelow.
Obtaining the PrivilegedCarbonContext
Obtain Obtains the
PrivilegedCarbonContext by using data stored in the current
Thread; current thread:
PrivilegedCarbonContext.getThreadLocalCarbonContext(). As a result, in cases like the deployers, where you can be sure that the deployment scheduler thread would set the
ThreadLocal data, you should directly call the
getThreadLocalCarbonContext method. You should have an idea, under which thread you are executing. It is better to resolve the
CarbonContext outside that util method, as opposed to resolving the CarbonContext within the method.