Hi

The stream consumer is stopped via a
java.util.concurrent.ExecutorService#shutdownNow

If you read its javadoc it says

* <p>There are no guarantees beyond best-effort attempts to stop
* processing actively executing tasks.  For example, typical
* implementations will cancel via {@link Thread#interrupt}, so any
* task that fails to respond to interrupts may never terminate.

I am not sure why the JDK thread pool cannot interrupt that readLine thread.

On Fri, Jul 28, 2017 at 6:12 AM, gludington <[email protected]> wrote:
> When I attempt to shutdown a camel context, the main thread stays open,
> seemingly parked on the consumer.  For example, using a small variation on
> the console sample (at end of message), which uses stream:in and stream:out,
> I can start up a context, either using a SpringCamelContext or using
> org.apache.camel.spring.Main.  However, when I stop the context using
> camelContext.stop() in a separate thread, the context stops, but not
> everything is released.  In the log, I will see all the messages, concluding
> with:
>
> 23:52:14.711 [pool-2-thread-1] INFO
> org.apache.camel.spring.SpringCamelContext - Apache Camel 2.19.0
> (CamelContext: camel-1) uptime 42.866 seconds
> 23:52:14.713 [pool-2-thread-1] INFO
> org.apache.camel.spring.SpringCamelContext - Apache Camel 2.19.0
> (CamelContext: camel-1) is shutdown in 27.621 seconds
>
> Stepping through the debugger I can see that StreamConsumer#doStop is
> called, but a thread dump shows the camel-1 thread is still parked on
> reading a line
>           at
> org.apache.camel.component.stream.StreamConsumer.readFromStream(StreamConsumer.java:171)
>           at
> org.apache.camel.component.stream.StreamConsumer.run(StreamConsumer.java:99)
>           at
> java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
>           at
> java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
>
> I saw similar behavior with a file consumer, as well.  Is there a proper way
> to shut down all consumers as well when shutting down a camel context, so
> that I can kill a specific spring context and release all resources without
> shutting down the entire application?
>
> The context in question:
> <camelContext xmlns="http://camel.apache.org/schema/spring";>
>         <route>
>
>         <from uri="stream:in?promptMessage=Enter something: "/>
>         <choice>
>                 <when>
>                 <simple>${body} == 'cash'</simple>
>                 <log message="I HAVE CASH" loggingLevel="INFO"
> logName="Test"/>
>             </when>
>             <when>
>                 <simple>${body} == 'credit'</simple>
>                                 <log message="GIVE ME CREDIT" 
> loggingLevel="INFO" logName="Test"/>
>             </when>
>             <otherwise>
>                 <log message="Excuse me, WHAT IS ${body}"
> loggingLevel="INFO" logName="Test"/>
>             </otherwise>
>         </choice>
>
>
>     <to uri="stream:out"/>
>         </route>
>     </camelContext>
>
> Thanks,
> Greg
>
>
>
> --
> View this message in context: 
> http://camel.465427.n5.nabble.com/Shutting-down-camel-and-consumers-tp5808223.html
> Sent from the Camel - Users mailing list archive at Nabble.com.



-- 
Claus Ibsen
-----------------
http://davsclaus.com @davsclaus
Camel in Action 2: https://www.manning.com/ibsen2

Reply via email to