How to "finalize" my Switchyard Service

Latest response

Have a need to perform 'cleanup' tasks in my org.switchyard.component.bean.Service when a shutdown, via undeploy or management shutdown, is performed. So far no variation of using a finalize method will work. Is there anyway to access and register a 'listener' from my service the org.apache.camel.impl.DefaultShutdownStrategy? Maybe this is someone is need to access via a ModelControllerClient?? Any suggestions very appreciated!

Responses

What exactly do you want to "cleanup" during undeployment that the container won't?

Service Bean calls a singleton implementation class which is turn has to spin up a runable "task thread". This thread does not finalize when the service bean is undeployed.

Not sure this is the best thing to be doing. See this thread [1] and [2].

[1] https://developer.jboss.org/thread/250395
[2] http://www.adam-bien.com/roller/abien/entry/legally_starting_threads_in_ejbs

Wow... ok, feel like a complete nub ;-)

The scenario is such... using Endpoint Router with drools to 'route' message instances from various bindings to their proper endpoints; in this case swithyard services. In several instances these various services need 'long running tasks' to pump status to outside systems via a reference binding. Since these status 'threads' need to run independently after an initial startup from a messages received and processed by the service bean, what would be the proper pattern for these tasks/threads?

Hi John

I'd suggest you raise a support case for this so our engineers can understand a little more about your business case and try and provide you with the best suggestion for your use case. However, from what you've written it sounds like you need to implement an @Asynchronous EJB. See [1] for the definition and [2] for an quickstart example.

[1] https://docs.oracle.com/javaee/6/tutorial/doc/gkkqg.html
[2] http://www.jboss.org/quickstarts/eap/ejb-asynchronous/