private void addToMemory(TaskProfile taskProfile) {
        Task oldTask = taskMap.get(taskProfile.getTaskId());
        if (oldTask != null) {
            oldTask.destroy();
            taskMap.remove(taskProfile.getTaskId());
            LOGGER.error("old task {} should not exist, try stop it first",
                    taskProfile.getTaskId());
        }
        try {
            Class<?> taskClass = Class.forName(taskProfile.getTaskClass());
            Task task = (Task) taskClass.newInstance();
            task.init(this, taskProfile, instanceBasicStore);
            taskMap.put(taskProfile.getTaskId(), task);
            runningPool.submit(task);
            LOGGER.info(
                    "add task {} into memory, taskMap size {}, runningPool task total {}, runningPool task active {}",
                    task.getTaskId(), taskMap.size(), runningPool.getTaskCount(),
                    runningPool.getActiveCount());
        } catch (Throwable t) {
            LOGGER.error("add task error: ", t);
        }
    }
add task to memory, if there is a record refer to the task id exist we need to destroy it first.
inlong-agent/agent-core/src/main/java/org/apache/inlong/agent/core/task/TaskManager.java