Tapestry Inversion of Control Container
Main article: Tapestry IoC
Contents
Table of Contents |
---|
exclude | Contents|Tapestry Inversion of Control Container|Related Articles |
---|
printable | false |
---|
|
Div |
---|
style | float:right |
---|
title | Related Articles |
---|
class | aui-label |
---|
|
Content by Label |
---|
showLabels | false |
---|
showSpace | false |
---|
title | Related Articles |
---|
cql | label = "ioc" and space = currentSpace() |
---|
|
|
...
This same concern applies to any long-lived resource (a thread, a database connection, a JMS queue connection) that a service may hold onto. Your code needs to know when the application has been undeployed and shutdown. This is actually quite easy, by adding some post-injection logic to your implementation class.
Code Block |
---|
controls | true |
---|
language | java |
---|
title | MyServiceImpl.java |
---|
linenumbers | true |
---|
|
public class MyServiceImpl implements MyService
{
private boolean shuttingDown;
private final Thread workerThread;
public MyServiceImpl()
{
workerThread = new Thread(. . .);
}
. . .
@PostInjection
public void startupService(RegistryShutdownHub shutdownHub)
{
shutdownHub.addRegistryShutdownListener(new Runnable()
{
public void run()
{
shuttingDown = true;
workerThread.interrupt();
}
});
}
}
|
...
Warning |
---|
It is not recommended that MyServiceImpl take RegistryShutdownHub as a constructor parameter and register itself as a listener inside the constructor. Doing so is an example of unsafe publishing, a remote an unlikely but potential thread safety issue. |
...