Explain the parent delegation model. Why does Tomcat break it for webapps?
Tests whether you really understand classloader isolation — core to plugin systems, app servers, and hot reload.
Three built-in classloaders: Bootstrap (rt.jar, native C++), Extension/Platform (jre/lib/ext or modules), Application (classpath).
Parent delegation: a classloader asks its parent first, only loads itself if parent fails. Rationale: core classes (java.lang.Object) always come from Bootstrap, can't be spoofed.
Tomcat flips this for WEB-INF/classes — each webapp loads its own classes first, so different wars can use different library versions in the same JVM.
SPI (ServiceLoader / JDBC driver) also breaks delegation via Thread.currentThread().getContextClassLoader(), so core code (in Bootstrap) can find implementations on the app classpath.
Same .class loaded by different classloaders = two different Class objects, ClassCastException even though names match. Key insight for plugin isolation.
Default is parent delegation — Bootstrap → Extension → Application, each delegates up before trying itself. This guarantees java.lang.* can't be replaced by a malicious jar. Two big deliberate violations: Tomcat's WebappClassLoader loads WEB-INF/classes first so different wars can ship different Jackson versions; and SPI via Thread.currentThread().getContextClassLoader() lets Bootstrap-loaded JDBC APIs find driver impls on the app classpath. Class identity = classloader + fully-qualified name. Same class, two loaders, two distinct Class objects — that's why hot reload frameworks throw ClassCastException when you hold a reference across a reload.
Java 9+ replaced "Extension classloader" with "Platform classloader" for modules — the hierarchy logic is the same.
ClassNotFoundException vs NoClassDefFoundError: first is "never found"; second is "found once but linking failed or loader-visibility issue".
HireMe AI (即答侠) pairs this question with the Tomcat/SPI examples so interviewers see you've shipped plugin systems, not just read a book.
Yes — extend ClassLoader and override findClass. Plugin frameworks, hot reload (JRebel), and OSGi all do this.
DriverManager is in rt.jar (Bootstrap), but driver impls are on the app classpath (Application). Bootstrap can't see Application, so it reaches "down" via the thread context classloader.
HireMe AI listens to your interview in real-time, detects questions, and generates instant answer suggestions — so you never freeze up again.
Try HireMe AI Free