Re: tomcat gracefull shutdown problem
Thx for reply, Do You think it would be hard to implement it in Tomcat ? It seems to be quite a useful feature. Regards Jakub On Tue, Jan 14, 2014 at 3:26 PM, Daniel Mikusa wrote: > On Jan 13, 2014, at 7:48 PM, Ja kub wrote: > > > I modified conf/context.xml > > I hoped tomcat would wait 60 seconds for request to end. > > No, it doesn't do this. It does not have an option for "graceful" restart > / shutdown like Apache HTTPD. If you want that behavior, you could setup a > proxy in front of Tomcat and use that to either temporarily handle the > requests (like send them to a maintenance page) or direct them to a > different Tomcat node (like with a cluster setup). In this way you can > slowly drain the requests from your Tomcat server and then safely restart / > shut it down. > > > But there are some problems with spring app, I get > > > > HTTP Status 503 - Servlet jsp is currently unavailable: > > > > I use tomcat 7.42 64 bit on windows 7 > > > > steps to reproduce: > > As mentioned above, Tomcat doesn't really have a graceful shutdown option, > at least not like HTTPD has graceful restart / shutdown options. > > Tomcat has two shutdown options. The first is a controlled shutdown (kill > -15 or the shutdown port) and this nicely gives applications deployed to > Tomcat the chance to clean up. This is normally what happens when you use > the shutdown script. The second is a kill -9, which just ends the process > immediately. > > Dan > > > > > use app from https://github.com/spring-projects/spring-petclinic > > > > git clone https://github.com/SpringSource/spring-petclinic.git > > > > to VetController class add: > > > >@RequestMapping("/vets/{delay}") > >public String showVetListDelayed(@PathVariable int delay, Map > Object> model) { > >// Here we are returning an object of type 'Vets' rather than a > > collection of Vet objects > >// so it is simpler for Object-Xml mapping > >Vets vets = new Vets(); > >vets.getVetList().addAll(this.clinicService.findVets()); > >model.put("vets", vets); > >try { > > Thread.sleep(1000*delay); > > } catch (InterruptedException e) { > > // TODO Auto-generated catch block > > e.printStackTrace(); > > } catch (Exception e) { > > e.printStackTrace(); > > } > >System.err.println("woken up ---"); > >return "vets/vetList"; > >} > > mvn clean install > > > > // copy from target to webapps > > > > go to > > http://localhost:8080/petclinic/vets/5 > > hit ctrl C > > > > app sleeps, wait until > > System.err.println("woken up ---"); executes > > but browser gets error. > > > > below is console log: > > > > Hibernate: select distinct vet0_.id as id1_5_0_, specialty2_.id as > > id1_2_1_, vet0_.first_ > > specialty2_.name as name2_2_1_, specialtie1_.vet_id as vet1_5_0__, > > specialtie1_.specialt > > join vet_specialties specialtie1_ on vet0_.id=specialtie1_.vet_id left > > outer join special > > alty2_.id order by vet0_.last_name, vet0_.first_name > > Jan 14, 2014 1:20:15 AM org.apache.catalina.core.StandardServer await > > INFO: A valid shutdown command was received via the shutdown port. > Stopping > > the Server in > > Jan 14, 2014 1:20:15 AM org.apache.coyote.AbstractProtocol pause > > INFO: Pausing ProtocolHandler ["http-apr-8080"] > > Jan 14, 2014 1:20:15 AM org.apache.coyote.AbstractProtocol pause > > INFO: Pausing ProtocolHandler ["ajp-apr-8009"] > > Jan 14, 2014 1:20:15 AM org.apache.catalina.core.StandardService > > stopInternal > > INFO: Stopping service Catalina > > Jan 14, 2014 1:20:16 AM org.apache.catalina.core.StandardWrapper unload > > INFO: Waiting for 1 instance(s) to be deallocated for Servlet [petclinic] > > woken up --- > > INFO XmlWebApplicationContext - Closing WebApplicationContext for > > namespace 'petclinic-s > > ]; parent: Root WebApplicationContext > > INFO XmlWebApplicationContext - Closing Root WebApplicationContext: > > startup date [Tue Ja > > INFO AnnotationMBeanExporter - Unregistering JMX-exposed beans on > shutdown > > INFO EhCacheManagerFactoryBean - Shutting down EhCache CacheManager > > INFO LocalContainerEntityManagerFactoryBean - Closing JPA > > EntityManagerFactory for persi > > Jan 14, 2014 1:20:22 AM org.apache.catalina.loader.WebappClassLoader > > clearReferencesJdbc > > SEVERE: The web application [/petclinic] registered the JDBC driver > > [org.hsqldb.jdbc.JDBC > > plication was stopped. To prevent a memory leak, the JDBC Driver has been > > forcibly unregi > > Jan 14, 2014 1:20:22 AM org.apache.catalina.loader.WebappClassLoader > > clearReferencesThrea > > SEVERE: The web application [/petclinic] appears to have started a thread > > named [PoolClea > > p it. This is very likely to create a memory leak. > > Jan 14, 2014 1:20:22 AM org.apache.coyote.AbstractProtocol stop > > INFO: Stopping ProtocolHandler ["http-apr-8080"] > > Jan 14, 2014 1:20:22 AM org.apache.coyote.Abstrac
Re: tomcat gracefull shutdown problem
On Jan 13, 2014, at 7:48 PM, Ja kub wrote: > I modified conf/context.xml > I hoped tomcat would wait 60 seconds for request to end. No, it doesn't do this. It does not have an option for "graceful" restart / shutdown like Apache HTTPD. If you want that behavior, you could setup a proxy in front of Tomcat and use that to either temporarily handle the requests (like send them to a maintenance page) or direct them to a different Tomcat node (like with a cluster setup). In this way you can slowly drain the requests from your Tomcat server and then safely restart / shut it down. > But there are some problems with spring app, I get > > HTTP Status 503 - Servlet jsp is currently unavailable: > > I use tomcat 7.42 64 bit on windows 7 > > steps to reproduce: As mentioned above, Tomcat doesn't really have a graceful shutdown option, at least not like HTTPD has graceful restart / shutdown options. Tomcat has two shutdown options. The first is a controlled shutdown (kill -15 or the shutdown port) and this nicely gives applications deployed to Tomcat the chance to clean up. This is normally what happens when you use the shutdown script. The second is a kill -9, which just ends the process immediately. Dan > > use app from https://github.com/spring-projects/spring-petclinic > > git clone https://github.com/SpringSource/spring-petclinic.git > > to VetController class add: > >@RequestMapping("/vets/{delay}") >public String showVetListDelayed(@PathVariable int delay, Map Object> model) { >// Here we are returning an object of type 'Vets' rather than a > collection of Vet objects >// so it is simpler for Object-Xml mapping >Vets vets = new Vets(); >vets.getVetList().addAll(this.clinicService.findVets()); >model.put("vets", vets); >try { > Thread.sleep(1000*delay); > } catch (InterruptedException e) { > // TODO Auto-generated catch block > e.printStackTrace(); > } catch (Exception e) { > e.printStackTrace(); > } >System.err.println("woken up ---"); >return "vets/vetList"; >} > mvn clean install > > // copy from target to webapps > > go to > http://localhost:8080/petclinic/vets/5 > hit ctrl C > > app sleeps, wait until > System.err.println("woken up ---"); executes > but browser gets error. > > below is console log: > > Hibernate: select distinct vet0_.id as id1_5_0_, specialty2_.id as > id1_2_1_, vet0_.first_ > specialty2_.name as name2_2_1_, specialtie1_.vet_id as vet1_5_0__, > specialtie1_.specialt > join vet_specialties specialtie1_ on vet0_.id=specialtie1_.vet_id left > outer join special > alty2_.id order by vet0_.last_name, vet0_.first_name > Jan 14, 2014 1:20:15 AM org.apache.catalina.core.StandardServer await > INFO: A valid shutdown command was received via the shutdown port. Stopping > the Server in > Jan 14, 2014 1:20:15 AM org.apache.coyote.AbstractProtocol pause > INFO: Pausing ProtocolHandler ["http-apr-8080"] > Jan 14, 2014 1:20:15 AM org.apache.coyote.AbstractProtocol pause > INFO: Pausing ProtocolHandler ["ajp-apr-8009"] > Jan 14, 2014 1:20:15 AM org.apache.catalina.core.StandardService > stopInternal > INFO: Stopping service Catalina > Jan 14, 2014 1:20:16 AM org.apache.catalina.core.StandardWrapper unload > INFO: Waiting for 1 instance(s) to be deallocated for Servlet [petclinic] > woken up --- > INFO XmlWebApplicationContext - Closing WebApplicationContext for > namespace 'petclinic-s > ]; parent: Root WebApplicationContext > INFO XmlWebApplicationContext - Closing Root WebApplicationContext: > startup date [Tue Ja > INFO AnnotationMBeanExporter - Unregistering JMX-exposed beans on shutdown > INFO EhCacheManagerFactoryBean - Shutting down EhCache CacheManager > INFO LocalContainerEntityManagerFactoryBean - Closing JPA > EntityManagerFactory for persi > Jan 14, 2014 1:20:22 AM org.apache.catalina.loader.WebappClassLoader > clearReferencesJdbc > SEVERE: The web application [/petclinic] registered the JDBC driver > [org.hsqldb.jdbc.JDBC > plication was stopped. To prevent a memory leak, the JDBC Driver has been > forcibly unregi > Jan 14, 2014 1:20:22 AM org.apache.catalina.loader.WebappClassLoader > clearReferencesThrea > SEVERE: The web application [/petclinic] appears to have started a thread > named [PoolClea > p it. This is very likely to create a memory leak. > Jan 14, 2014 1:20:22 AM org.apache.coyote.AbstractProtocol stop > INFO: Stopping ProtocolHandler ["http-apr-8080"] > Jan 14, 2014 1:20:22 AM org.apache.coyote.AbstractProtocol stop > INFO: Stopping ProtocolHandler ["ajp-apr-8009"] > Jan 14, 2014 1:20:22 AM org.apache.coyote.AbstractProtocol destroy > INFO: Destroying ProtocolHandler ["http-apr-8080"] > Jan 14, 2014 1:20:22 AM org.apache.coyote.AbstractProtocol destroy > INFO: Destroying ProtocolHandler ["ajp-apr-8009"] > > > Regards > Jakub --
Re: tomcat gracefull shutdown problem
even with unloadDelay="6" in conf/context.xml probably Servlet jsp is undeployed before spring servlet, and when spring servlet wants to use it to render jsp - it is already undeployed (and results in : HTTP Status 503 - Servlet jsp is currently unavailable) question is how to make Servlet jsp undeployed as last servlet, afaik there is no priority opposite to 100 deciding when servlet is undeployed. is there any solution in tomcat ? can we prevent tomcat from unloading servlets for some time ? can we tell tomcat to stop accept new requests ? Regards Jakub On Tue, Jan 14, 2014 at 1:48 AM, Ja kub wrote: > I modified conf/context.xml > I hoped tomcat would wait 60 seconds for request to end. > But there are some problems with spring app, I get > > HTTP Status 503 - Servlet jsp is currently unavailable: > > I use tomcat 7.42 64 bit on windows 7 > > steps to reproduce: > > use app from https://github.com/spring-projects/spring-petclinic > > git clone https://github.com/SpringSource/spring-petclinic.git > > to VetController class add: > > @RequestMapping("/vets/{delay}") > public String showVetListDelayed(@PathVariable int delay, Map Object> model) { > // Here we are returning an object of type 'Vets' rather than a > collection of Vet objects > // so it is simpler for Object-Xml mapping > Vets vets = new Vets(); > vets.getVetList().addAll(this.clinicService.findVets()); > model.put("vets", vets); > try { > Thread.sleep(1000*delay); > } catch (InterruptedException e) { > // TODO Auto-generated catch block > e.printStackTrace(); > } catch (Exception e) { > e.printStackTrace(); > } > System.err.println("woken up ---"); > return "vets/vetList"; > } > > mvn clean install > > // copy from target to webapps > > go to > http://localhost:8080/petclinic/vets/5 > hit ctrl C > > app sleeps, wait until > System.err.println("woken up ---"); executes > but browser gets error. > > below is console log: > > Hibernate: select distinct vet0_.id as id1_5_0_, specialty2_.id as > id1_2_1_, vet0_.first_ > specialty2_.name as name2_2_1_, specialtie1_.vet_id as vet1_5_0__, > specialtie1_.specialt > join vet_specialties specialtie1_ on vet0_.id=specialtie1_.vet_id left > outer join special > alty2_.id order by vet0_.last_name, vet0_.first_name > Jan 14, 2014 1:20:15 AM org.apache.catalina.core.StandardServer await > INFO: A valid shutdown command was received via the shutdown port. > Stopping the Server in > Jan 14, 2014 1:20:15 AM org.apache.coyote.AbstractProtocol pause > INFO: Pausing ProtocolHandler ["http-apr-8080"] > Jan 14, 2014 1:20:15 AM org.apache.coyote.AbstractProtocol pause > INFO: Pausing ProtocolHandler ["ajp-apr-8009"] > Jan 14, 2014 1:20:15 AM org.apache.catalina.core.StandardService > stopInternal > INFO: Stopping service Catalina > Jan 14, 2014 1:20:16 AM org.apache.catalina.core.StandardWrapper unload > INFO: Waiting for 1 instance(s) to be deallocated for Servlet [petclinic] > woken up --- > INFO XmlWebApplicationContext - Closing WebApplicationContext for > namespace 'petclinic-s > ]; parent: Root WebApplicationContext > INFO XmlWebApplicationContext - Closing Root WebApplicationContext: > startup date [Tue Ja > INFO AnnotationMBeanExporter - Unregistering JMX-exposed beans on shutdown > INFO EhCacheManagerFactoryBean - Shutting down EhCache CacheManager > INFO LocalContainerEntityManagerFactoryBean - Closing JPA > EntityManagerFactory for persi > Jan 14, 2014 1:20:22 AM org.apache.catalina.loader.WebappClassLoader > clearReferencesJdbc > SEVERE: The web application [/petclinic] registered the JDBC driver > [org.hsqldb.jdbc.JDBC > plication was stopped. To prevent a memory leak, the JDBC Driver has been > forcibly unregi > Jan 14, 2014 1:20:22 AM org.apache.catalina.loader.WebappClassLoader > clearReferencesThrea > SEVERE: The web application [/petclinic] appears to have started a thread > named [PoolClea > p it. This is very likely to create a memory leak. > Jan 14, 2014 1:20:22 AM org.apache.coyote.AbstractProtocol stop > INFO: Stopping ProtocolHandler ["http-apr-8080"] > Jan 14, 2014 1:20:22 AM org.apache.coyote.AbstractProtocol stop > INFO: Stopping ProtocolHandler ["ajp-apr-8009"] > Jan 14, 2014 1:20:22 AM org.apache.coyote.AbstractProtocol destroy > INFO: Destroying ProtocolHandler ["http-apr-8080"] > Jan 14, 2014 1:20:22 AM org.apache.coyote.AbstractProtocol destroy > INFO: Destroying ProtocolHandler ["ajp-apr-8009"] > > > Regards > Jakub >
tomcat gracefull shutdown problem
I modified conf/context.xml I hoped tomcat would wait 60 seconds for request to end. But there are some problems with spring app, I get HTTP Status 503 - Servlet jsp is currently unavailable: I use tomcat 7.42 64 bit on windows 7 steps to reproduce: use app from https://github.com/spring-projects/spring-petclinic git clone https://github.com/SpringSource/spring-petclinic.git to VetController class add: @RequestMapping("/vets/{delay}") public String showVetListDelayed(@PathVariable int delay, Map model) { // Here we are returning an object of type 'Vets' rather than a collection of Vet objects // so it is simpler for Object-Xml mapping Vets vets = new Vets(); vets.getVetList().addAll(this.clinicService.findVets()); model.put("vets", vets); try { Thread.sleep(1000*delay); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (Exception e) { e.printStackTrace(); } System.err.println("woken up ---"); return "vets/vetList"; } mvn clean install // copy from target to webapps go to http://localhost:8080/petclinic/vets/5 hit ctrl C app sleeps, wait until System.err.println("woken up ---"); executes but browser gets error. below is console log: Hibernate: select distinct vet0_.id as id1_5_0_, specialty2_.id as id1_2_1_, vet0_.first_ specialty2_.name as name2_2_1_, specialtie1_.vet_id as vet1_5_0__, specialtie1_.specialt join vet_specialties specialtie1_ on vet0_.id=specialtie1_.vet_id left outer join special alty2_.id order by vet0_.last_name, vet0_.first_name Jan 14, 2014 1:20:15 AM org.apache.catalina.core.StandardServer await INFO: A valid shutdown command was received via the shutdown port. Stopping the Server in Jan 14, 2014 1:20:15 AM org.apache.coyote.AbstractProtocol pause INFO: Pausing ProtocolHandler ["http-apr-8080"] Jan 14, 2014 1:20:15 AM org.apache.coyote.AbstractProtocol pause INFO: Pausing ProtocolHandler ["ajp-apr-8009"] Jan 14, 2014 1:20:15 AM org.apache.catalina.core.StandardService stopInternal INFO: Stopping service Catalina Jan 14, 2014 1:20:16 AM org.apache.catalina.core.StandardWrapper unload INFO: Waiting for 1 instance(s) to be deallocated for Servlet [petclinic] woken up --- INFO XmlWebApplicationContext - Closing WebApplicationContext for namespace 'petclinic-s ]; parent: Root WebApplicationContext INFO XmlWebApplicationContext - Closing Root WebApplicationContext: startup date [Tue Ja INFO AnnotationMBeanExporter - Unregistering JMX-exposed beans on shutdown INFO EhCacheManagerFactoryBean - Shutting down EhCache CacheManager INFO LocalContainerEntityManagerFactoryBean - Closing JPA EntityManagerFactory for persi Jan 14, 2014 1:20:22 AM org.apache.catalina.loader.WebappClassLoader clearReferencesJdbc SEVERE: The web application [/petclinic] registered the JDBC driver [org.hsqldb.jdbc.JDBC plication was stopped. To prevent a memory leak, the JDBC Driver has been forcibly unregi Jan 14, 2014 1:20:22 AM org.apache.catalina.loader.WebappClassLoader clearReferencesThrea SEVERE: The web application [/petclinic] appears to have started a thread named [PoolClea p it. This is very likely to create a memory leak. Jan 14, 2014 1:20:22 AM org.apache.coyote.AbstractProtocol stop INFO: Stopping ProtocolHandler ["http-apr-8080"] Jan 14, 2014 1:20:22 AM org.apache.coyote.AbstractProtocol stop INFO: Stopping ProtocolHandler ["ajp-apr-8009"] Jan 14, 2014 1:20:22 AM org.apache.coyote.AbstractProtocol destroy INFO: Destroying ProtocolHandler ["http-apr-8080"] Jan 14, 2014 1:20:22 AM org.apache.coyote.AbstractProtocol destroy INFO: Destroying ProtocolHandler ["ajp-apr-8009"] Regards Jakub