我想了解tomcat操作的内部原理并了解流程。
为此,我创建了一个 servlet -
public class TestServlet extends HttpServlet {
//Breakpoint set on constructor
public TestServlet() {
}
}
我在源查找目录中包含了 tomcat 源代码,并以调试模式启动了服务器。以下是调试器在我的断点处停止时的堆栈跟踪 -
Daemon Thread [localhost-startStop-1] (Suspended (entry into method <init> in TestServlet))
owns: StandardWrapper (id=39)
owns: StandardContext (id=40)
TestServlet.<init>() line: 12
NativeConstructorAccessorImpl.newInstance0(Constructor, Object[]) line: not available [native method]
NativeConstructorAccessorImpl.newInstance(Object[]) line: 39
DelegatingConstructorAccessorImpl.newInstance(Object[]) line: 27
Constructor<T>.newInstance(Object...) line: 513
Class<T>.newInstance0() line: 355
Class<T>.newInstance() line: 308
DefaultInstanceManager.newInstance(String) line: 138
StandardWrapper.loadServlet() line: 1144
StandardWrapper.load() line: 1088
StandardContext.loadOnStartup(Container[]) line: 5123
StandardContext.startInternal() line: 5407
StandardContext(LifecycleBase).start() line: 150
ContainerBase$StartChild.call() line: 1559
ContainerBase$StartChild.call() line: 1549
FutureTask$Sync.innerRun() line: 303
FutureTask<V>.run() line: 138
ThreadPoolExecutor$Worker.runTask(Runnable) line: 886
ThreadPoolExecutor$Worker.run() line: 908
Thread.run() line: 662
如您所见,tomcat 启动了一个新的守护线程来处理TestServlet
. 如果我从这个位置走出来,它会回溯到运行然后停止。但是我想了解主服务器逻辑。我应该怎么做才能进入org.apache.catalina.startup.Bootstrap
课堂? (或在主启动线程上运行的其他类)