Jason Greene [
http://community.jboss.org/people/jason.greene] created the discussion
"Re: can I avoid a service to block as7 startup ?"
To view the discussion, visit:
http://community.jboss.org/message/631213#631213
--------------------------------------------------------------
Lifecycle.execute() reuses the same MSC thread pool, so blocking tasks are off limits
there as well. It's facility is for uncommon use cases (arguably it shouldn't
exist at all).
If you want to do an async start task do the following steps:
1. In your start() method call LifecycleContext.asynchronous. This tells MSC not to assume
a method return indicates completion
2. In your start() method create a Thread (or a pool depending on your use case). For
example, Executors.newSingleThreadExecutor.
3. Construct a new instance of your blocking task and pass it a copy of the StartContext
(LifeCyclecontext)
4. The task's run method should be written to perform the blocking task and call
complete() on the Lifecycle context when done
5. Pass and execute the task instance to the pool/thread you created in step 2. This will
cause your blocking operation to start in another thread
6. Return from your start method.
What will happen after that point is that the service will remain in STARTING state until
the task calls complete(), once that happens it will become available to other
dependencies.
--------------------------------------------------------------
Reply to this message by going to Community
[
http://community.jboss.org/message/631213#631213]
Start a new discussion in JBoss AS7 Development at Community
[
http://community.jboss.org/choose-container!input.jspa?contentType=1&...]