Archived

This forum has been archived. Please start a new discussion on GitHub.

global variable and thread issue in ice

Hello,

I'm new to Ice. I want to store some aplication-wide variables in ice server application (this is reguler ice application, not using icebox / icegrid). I did this by placing those global variables in the main class of the object. So far so good for 1 client, but I wonder is this the correct way to do such thing ?. I mean, I'm afraid that every client will have their own fresh copy of server instance in separate thread instead of one instance of server object for all client. How ice server serve client's request, 1 instance for all clients or 1 instance (in separate thread) for 1 client ?.

Thanks in advance for your help,
regards,
solikhin

Comments

  • benoit
    benoit Rennes, France
    Hi,

    I assume you meant "servant" by "main class of the object" (see this FAQ for the correct terminology). It's not quite clear to me what you're doing (perhaps you can post some sample code to demonstrate it?). But if you have registered the servant with the object adapter and your clients invoke on the Ice object incarnated by the servant with a proxy that only points to this Ice object, your clients will use the same instance of the object.

    Cheers,
    Benoit.
  • re:global variable and thread issue in ice

    Thanks for your quick reply,

    Here is an ilustration on what I mean with "the main class of the object" :

    class HelloI : public Demo::Hello
    {
    public:
    virtual void sayHello(int delay,const Ice::current&) const;
    virtual void shutdown(const Ice::current&);

    // Here I put some global variables
    // ie: some connection to the "in memory" database
    }

    Those variables will be initialized during the creation of those class. I expect to only have 1 instance of this class (regardless of the number of client connection) so that the content of in memory database will be consistent on all client. Is that the correct way to do such thing ?.
  • benoit
    benoit Rennes, France
    Yes, there will only be one servant instance for the Ice object if you register this servant with the object adapter. Invocations from different clients will be dispatched with the same servant instance.

    Cheers,
    Benoit.