[jboss-as7-dev] Important note for MSC Service authors
David M. Lloyd
david.lloyd at redhat.com
Wed Apr 13 15:55:03 EDT 2011
When writing MSC service implementations, your start() and stop()
methods must never block. This means these methods must not:
- Establish or use network connections
- Wait for network connections
- Sleep
- Wait on a condition
- Wait on a count down latch
- Call any method which may do any of the above
- Wait for termination of a thread pool or other service
- Wait for another service to change state!
If your service start/stop involves any of these tasks, you must use the
asynchronous start/stop mechanism (context.asynchronous()) and do one of
the following:
- Initiate your task in start()/stop(), and utilize a callback (NIO,
ThreadPoolExecutor.terminated(), etc.) to call context.complete() when
your start/stop completes instead of blocking
- Delegate your blocking task to a thread pool (Executor) which calls
context.complete() when done
- Use proper dependencies instead of explicitly waiting for services in
your start/stop
Failure to do so can cause startup delays and can even lock up the MSC
state machine! If you are unsure what the best approach is for your
problem, ping me in #jboss-as7 or #jboss-msc and I'll help you out.
--
- DML
More information about the jboss-as7-dev
mailing list