private void traverseMemoryTasksToStore() {
        instanceMap.values().forEach((instance) -> {
            InstanceProfile profileFromStore =
                    instanceStore.getInstance(instance.getTaskId(), instance.getInstanceId());
            if (profileFromStore == null) {
                deleteFromMemory(instance.getInstanceId());
                return;
            }
            InstanceStateEnum stateFromStore = profileFromStore.getState();
            if (stateFromStore != InstanceStateEnum.DEFAULT) {
                deleteFromMemory(instance.getInstanceId());
            }
            if (AgentUtils.getCurrentTime() - instance.getLastHeartbeatTime() > INSTANCE_KEEP_ALIVE_MS) {
                LOGGER.error("instance heartbeat timeout, id: {}, will be deleted from memory",
                        instance.getInstanceId());
                deleteFromMemory(instance.getInstanceId());
            }
        });
    }
thread for core thread.

@return runnable profile.
inlong-agent/agent-core/src/main/java/org/apache/inlong/agent/core/instance/InstanceManager.java