package com.xxzhwx.core.runs;

import com.xxzhwx.core.net.Cmd;
import com.xxzhwx.core.queue.BaseQueue;

import java.util.concurrent.TimeUnit;

public abstract class AbstractCmdRunnable implements Runnable {
    private BaseQueue<Cmd> cmdQueue;

    public AbstractCmdRunnable(BaseQueue<Cmd> cmdQueue) {
        this.cmdQueue = cmdQueue;
    }

    public void run() {
        for (;;) {
            Cmd cmd;
            while (cmdQueue.size() > 0) {
                cmd = cmdQueue.poll();
                if (cmd != null) {
                    handleCmd(cmd);
                }
            }

            try {
                TimeUnit.MILLISECONDS.sleep(10);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }

    public abstract  void handleCmd(Cmd cmd);
}

@@ -200,16 +200,59 @@
 nable %7B%0A
+    private BaseQueue%3CRunnable%3E taskQueue;%0A
     priv
@@ -356,78 +356,414 @@
 his.
-cmdQueue = cmdQueue;%0A    %7D%0A%0A    public void run() %7B%0A        for (;;) %7B
+taskQueue = new BaseQueue%3C%3E();%0A        this.cmdQueue = cmdQueue;%0A    %7D%0A%0A    public void submitTask(Runnable task) %7B%0A        taskQueue.put(task);%0A    %7D%0A%0A    public void run() %7B%0A        for (;;) %7B%0A            Runnable task;%0A            while (taskQueue.size() %3E 0) %7B%0A                task = taskQueue.poll();%0A                if (task != null) %7B%0A                    task.run();%0A                %7D%0A            %7D%0A
 %0A   

Support executing tasks in the main loop(Command Runnable).