开发者

Supervising multiple gen_servers with same module / different arguments

I have a OTP application comprising a single supervisor supervising a small number of gen_servers. A typical child specification is as follows:

{my_server,
  {my_server, start_link, [123]},
  permanent, 
  5000, 
  worker,
  [my_server]}

No problems so far.

I now want to an add extra gen_server to the supervisor structure, using the same module Module/Fn开发者_如何学运维 as above, but different arguments, eg

{my_server_2,
  {my_server, start_link, [123]},
  permanent, 
  5000, 
  worker,
  [my_server_2]}

I thought this would work, but no:

=SUPERVISOR REPORT==== 15-Apr-2010::16:50:13 ===
     Supervisor: {local,my_sup}
     Context:    start_error
     Reason:     {already_started,<0.179.0>}
     Offender:   [{pid,undefined},
                  {name,my_server_2},
                  {mfa,{my_server,start_link,[]}},
                  {restart_type,permanent},
                  {shutdown,5000},
                  {child_type,worker}]

Do the module arguments in the second element of each child specification need to be different ?

Thanks,

Justin


My guess is that my_server registers its name using using gen_server:start_link/4, so that when the second one tries to start it can't because the name is already taken. The gen_servers will either have to start without a name (gen_server:start_link/3) or with different names.

It seems strange to vary the last element of the child spec, which identifies the list of modules used by the worker. Is this really what you intend?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜