[erlang-questions] Staring more than one instance of a gen_server
Anton Krasovsky
anton.krasovsky@REDACTED
Sat Oct 16 19:22:16 CEST 2010
Ken,
the usual way of starting multiple instances of the same gen_server
module is to use
start_link/3 function. However, since start_link/3 will not register
new process you'll need
to hold on to Pid of newly created process and use it later when
calling your server with gen_server:cast or gen_server:call.
However, it's the best practice to use supervisors just as Ahmed suggested.
Regards,
Anton
On Sat, Oct 16, 2010 at 2:34 PM, Ken Robinson <kenrobinsonster@REDACTED> wrote:
> Hi Ahmed,
> Thanks for your reply.
> I read that part of the documentation. I feel I want some less dynamic.
> I read some of the gen_server doco
> (http://www.erlang.org/doc/man/gen_server.html) where it referred to
> the start_link function:
> start_link(ServerName, Module, Args, Options) -> Result
> ...
> ServerName = {local,Name} | {global,GlobalName}
> I'm going to try changing the Id to the module name plus a number then
> making the ServerName the same as that.
> Ken.
>
> {Id, StartFunc, Restart, Shutdown, Type, Modules} from the
> On Fri, Oct 15, 2010 at 6:31 AM, Ahmed Omar <spawn.think@REDACTED> wrote:
>> Hi Ken,
>> It all depends on your purposes. If you want to start these processes as a
>> part of a supervision tree, so you would probably like to use
>> simple-one-for-one strategy and children dynamically
>> supervisor:start_child(Sup, List)
>> http://www.erlang.org/doc/design_principles/sup_princ.html#id67619
>> On Thu, Oct 14, 2010 at 5:15 PM, Ken Robinson <kenrobinsonster@REDACTED>
>> wrote:
>>>
>>> Hi All,
>>> If I wanted to start more than one instance of a gen_server what is
>>> the best practice? The gen_servers would be exactly the same except
>>> for the seeding parameters. From what I've found I could use the child
>>> spec and seed with specific names through the arguments like so:
>>> start_link(PortNumber, MySpecialName) -> gen_server:start_link({local,
>>> MySpecialName, ?MODULE, PortNumber, []).
>>> Would that work?
>>> --
>>> regards,
>>> Ken Robinson
>>>
>>> ________________________________________________________________
>>> erlang-questions (at) erlang.org mailing list.
>>> See http://www.erlang.org/faq.html
>>> To unsubscribe; mailto:erlang-questions-unsubscribe@REDACTED
>>>
>>
>>
>>
>> --
>> Best Regards,
>> - Ahmed Omar
>> http://nl.linkedin.com/in/adiaa
>> Follow me on twitter
>> @spawn_think
>>
>
>
>
> --
> regards,
> Ken Robinson
> Mob +61438681120
> Home +61738523767
> Work +61733063137
>
> ________________________________________________________________
> erlang-questions (at) erlang.org mailing list.
> See http://www.erlang.org/faq.html
> To unsubscribe; mailto:erlang-questions-unsubscribe@REDACTED
>
>
More information about the erlang-questions
mailing list