<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def _instance(self):
 global clients global runtimeInstances """ This method is used to get the Application instance previously created managing on this, it is possible to switch to "single instance for multiple clients" or "multiple instance for multiple clients" execution way """


        self.session = 0
        #checking previously defined session
        if 'cookie' in self.headers:
            self.session = parse_session_cookie(self.headers['cookie'])
            #if not a valid session id
            if self.session == None:
                self.session = 0
            if not self.session in clients.keys():
                self.session = 0

        #if no session id
        if self.session == 0:
            if self.server.multiple_instance:
                self.session = int(time.time()*1000)
            #send session to browser
            del self.headers['cookie']

        #if the client instance doesn't exist
        if not(self.session in clients):
            self.update_interval = self.server.update_interval

            from remi import gui
            
            head = gui.HEAD(self.server.title)
            # use the default css, but append a version based on its hash, to stop browser caching
            head.add_child('internal_css', "<link href='/res:style.css' rel='stylesheet' />\n")
            
            body = gui.BODY()
            body.onload.connect(self.onload)
            body.onerror.connect(self.onerror)
            body.ononline.connect(self.ononline)
            body.onpagehide.connect(self.onpagehide)
            body.onpageshow.connect(self.onpageshow)
            body.onresize.connect(self.onresize)
            self.page = gui.HTML()
            self.page.add_child('head', head)
            self.page.add_child('body', body)

            if not hasattr(self, 'websockets'):
                self.websockets = []

            self.update_lock = threading.RLock()

            if not hasattr(self, '_need_update_flag'):
                self._need_update_flag = False
                self._stop_update_flag = False
                if self.update_interval > 0:
                    self._update_thread = threading.Thread(target=self._idle_loop)
                    self._update_thread.setDaemon(True)
                    self._update_thread.start()

            runtimeInstances[str(id(self))] = self
            clients[self.session] = self
        else:
            #restore instance attributes
            client = clients[self.session]

            self.websockets = client.websockets
            self.page = client.page

            self.update_lock = client.update_lock

            self.update_interval = client.update_interval
            self._need_update_flag = client._need_update_flag
            if hasattr(client, '_update_thread'):
                self._update_thread = client._update_thread
                
        net_interface_ip = self.headers.get('Host', "%s:%s"%(self.connection.getsockname()[0],self.server.server_address[1]))
        websocket_timeout_timer_ms = str(self.server.websocket_timeout_timer_ms)
        pending_messages_queue_length = str(self.server.pending_messages_queue_length)
        self.page.children['head'].set_internal_js(net_interface_ip, pending_messages_queue_length, websocket_timeout_timer_ms)