Hi Devs,
Code snippets similar to below can be seen in some places where threads
wait till "terminated" variable becomes true . The variable is set to true,
when the component is deactivated. IMO this is bit hard to maintain.
// Keep the thread live until terminated
while (!terminated) {
try {
Thread.sleep(1000);
} catch (InterruptedException ignore) {
}
}
if (log.isInfoEnabled()) {
log.info("Autoscaler topology receiver thread terminated");
}
protected void deactivate(ComponentContext context) {
asTopologyReceiver.terminate();
autoscalerHealthStatEventReceiver.terminate();
}
How about adding a thread executor as [1] to what threads are added at
creation time and executor is shutdown when component is deactivated.
[1]
http://www.vogella.com/tutorials/JavaConcurrency/article.html#threadpools
--
Udara Liyanage
Software Engineer
WSO2, Inc.: http://wso2.com
lean. enterprise. middleware
web: http://udaraliyanage.wordpress.com
phone: +94 71 443 6897