This documentation is for WSO2 Carbon 4.4.1. View documentation for the latest release.
Page Comparison - CarbonContext API (v.8 vs v.9) - Carbon 4.3.0 - WSO2 Documentation
Due to a known issue do not use JDK1.8.0_151 with WSO2 products. Use JDK 1.8.0_144 until JDK 1.8.0_162-ea is released.

Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Obtain the PrivilegedCarbonContext from by using data stored in the 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.

...

Info

Always follow the following template when you carryout the latter mentioned steps:

Code Block
try{
    PrivilegedCarbonContext.startTenantFlow();
    PrivilegedCarbonContext privilegedCarbonContext =
               PrivilegedCarbonContext.getThreadLocalCarbonContext()
   privilegedCarbonContext.setTenantId(tenantId);
   privilegedCarbonContext.setTenantDomain(tenantDomain);
   // set other stuff like registry etc. if needed

  doSomething();
} finally {
   PrivilegedCarbonContext.endTenantFlow();
}

...