Class loadinghard5-8 years

Parent delegation means a class loader asks its parent first, and a parent has no way to ask a child. So how does `DriverManager` — loaded by the bootstrap loader, part of the core JDK — ever find a JDBC driver class that lives in application code, sitting on a child loader several levels below it?

It doesn't go through delegation at all — it uses a deliberate side channel that has nothing to do with the parent-child hierarchy: the thread context class loader (TCCL). Every Thread carries its own class loader reference, set to the application loader by default, that bootstrap-loaded code can explicitly ask for and load through instead of using its own (bootstrap) loader or the normal delegation chain. ServiceLoader.load(...) does exactly this internally, which is how JDBC driver auto-registration, JAXP parser lookup and JNDI provider mechanisms all work without any core JDK class needing a direct reference to application code — parent delegation only lets a loader reach upward toward its ancestors, and the TCCL is the JDK's answer to code that structurally needs to reach downward instead.

The lesson behind it →
More on Class loading