0

Because I found the method named bindThread() is invoked multiple times at class named StandardContext in Tomcat 7 source code, especially in the method named startInternal(). I do not understand why need to call this method multiple times.

Actually the bindThread() is set the thread context classloader, but I don't konw why still use bindThread() and unbindThread() method pair in the startInternal() invoke multiple times.

JasonMArcher
  • 14,195
  • 22
  • 56
  • 52
tyrion
  • 13
  • 3

1 Answers1

0

Web application start and stop normally happens with the container class loader in effect. Some parts of the start (and stop) process (e.g. firing the application listeners) needs to take place with the web application class loader in effect. bindThread() and unbindThread() are the methods that switch to the web application class loader and back again respectively. The various elements of start and stop have to happen in a specific order so it is necessary to switch back and forth between class loaders.

Mark Thomas
  • 16,339
  • 1
  • 39
  • 60
  • As you said, many elements of start an stop have to happen in a specific order.But i think only in the startInternal() invoke bindThread on the beginning of the method, and invoke unbindThread on the end of the method, just invoke once. – tyrion Oct 22 '13 at 10:10
  • Do you mean the elements need different class loader?For example, some elements need thread context class loader, and some elements need current class loader, do i understand right? – tyrion Oct 22 '13 at 10:19
  • Yes, only some elements require the web application class loader. Others require the current class loader. – Mark Thomas Oct 22 '13 at 18:58