掲示板

DXP/7 - How to force-stop a running module?

thumbnail
6年前 に Fernando Fernandez によって更新されました。

DXP/7 - How to force-stop a running module?

Expert 投稿: 396 参加年月日: 07/08/22 最新の投稿
Hi all,

I have a module that runs a task for several hours. In the middle of the task execution I need to stop it because it has a bug (or whatever) and I need to install a new version and restart.

Just uninstalling the module doesn't solve this. The task continues to run.

Can this be done without shutting down the server?

TIA

Fernando
thumbnail
6年前 に Olaf Kock によって更新されました。

RE: DXP/7 - How to force-stop a running module? (回答)

Liferay Legend 投稿: 6403 参加年月日: 08/09/23 最新の投稿
Fernando Fernandez:
I have a module that runs a task for several hours. In the middle of the task execution I need to stop it because it has a bug (or whatever) and I need to install a new version and restart.


OSGi will not magically terminate code for you - you'll have to do this on your own. It will only make sure that the services won't be bound and returned later - and that all dependent modules will be stopped. You can easily wreak havoc with the system and generate unexpected results by using the wrong coding style - e.g. keeping your own cached references to services (that might long have been stopped) or running long-running threads that have been started by services that might long have been stopped.

As always with concurrent programming, you should include a method to interrupt a long running operation - there are too many options to name them all. Flags are one thing, Executors are another one. Read the book "Concurrent Java" for more.

But, internalize: OSGi modifies the available services etc. - it won't remove any references that you have outside of the control of the OSGi runtime. It's just not that kind of an environment. Also: The garbage collector will only free up space for objects that don't have a reference any more. By introducing your own references, you can easily circumvent proper cleanup. And it's absolutely not OSGi's fault.

This might have been a bit more intense of an answer than you expected, but it's quite important to get the difference between what OSGi can do for you, and what it can't.
thumbnail
6年前 に Fernando Fernandez によって更新されました。

RE: DXP/7 - How to force-stop a running module?

Expert 投稿: 396 参加年月日: 07/08/22 最新の投稿
Hi Olaf,

Yes, intense but quite useful. :-)

Thanks!

Fernando