3

We've been having a discussion at work about shutting down tomcat when doing processing with Spring Integration.

We are wondering if Spring (Spring Integration), by default, processes all messages in progress on an inbound channel before it says to Tomcat it's ready to shut down?

My hunch is the Spring container would free all available resources, including blocking processing anything new onto a channel, before it told Tomcat it was ready to shut down. Only an idea though and I need to do a good bit of research. Is there something we have to add to make sure shutdown occurs best using Tomcat?

Research: So far looks like something like 'fire and forget' exists on outbound channel adapter so inbound channels probably include the same sort of thing.

Community
  • 1
  • 1
Crowie
  • 3,220
  • 7
  • 28
  • 48

2 Answers2

5

You can also use the destroy-method="cleanUp" for spring bean. You can clean all your resource from this method before destroying the bean.

Ashish Chaurasia
  • 1,747
  • 17
  • 23
  • Sounds good if you can do that before it shuts down but it makes me think something else. Using that approach would you call some sort of 'stop recieving' message on the inbound channel when a Tomcat shutdown event occurred i.e how would you stop listening on the inbound queue? I suppose the destroy method could stop an inbound adapter/channel listening.... – Crowie Aug 29 '13 at 13:21
  • first this method execution completes after that bean is destroy. – Ashish Chaurasia Aug 29 '13 at 13:25
3

No; when you stop Tomcat, the application context is torn down and Spring Integration doesn't have any control.

We introduced a new Orderly Shutdown feature in 2.2 using a JMX operation that allows stopping all active components (pollers, JMS listener containers, etc) then waiting some time for messages to quiesce. Some endpoints (such as the http inbound) are aware of this state and won't allow new requests to come in, while staying active to handle active threads.

It's not a perfect solution but it covers the vast majority of use cases.

brass monkey
  • 5,841
  • 10
  • 36
  • 61
Gary Russell
  • 166,535
  • 14
  • 146
  • 179
  • I'm invoking the `stopActiveComponents` operation from jconsole on `IntegrationMBeanExporter` and it isn't working. It says that the operation completed successfully, but spring integration components are all still running. Any ideas? – Ryan Walls Feb 20 '14 at 22:53
  • What do you mean by "running" ? - turn on DEBUG logging and you should see the progress of the shutdown. – Gary Russell Feb 20 '14 at 23:05