erlang supervisor restart strategy

I would like to start several processes as children of a given supervisor. The restart strategy is one_for_one For my needs, every process which terminates should be restarted after a given amount of time (eg 20 seconds).

How can this be done? Maybe with a delay in the init or in the terminate functions in combination with:

Shutdown = brutal_kill | integer() >=0 | infinity

Is there a better way to achieve this?


Don't use init/1 for this. While init is running, the supervisor is blocked. It is better to start up the process right away, but only let it register itself for operations like this after it has waited for 20 seconds. You could use a simple erlang:send_after(..) call in the init to trigger this startup delay.

I don't like the termination thing either. Perhaps have a close-down state in which you linger for a bit before termination. This could perhaps make sure that nobody else runs while you are doing. I'd recommend that if you are in control of when to close down. Simply enter this state and then await a timer trigger like the above. Note though that this solution will only free up external resources after the grace period (files, ETS tables, sockets) - unless explicitly freed.

链接地址: http://www.djcxy.com/p/6506.html

上一篇: erlang主管处理ibrowse的最佳方式:发送

下一篇: erlang管理员重启策略