Package com.sogou.qadev.service.cynthia.util

Source Code of com.sogou.qadev.service.cynthia.util.ScriptExecuteThread

package com.sogou.qadev.service.cynthia.util;

import bsh.EvalError;
import bsh.Interpreter;

import com.sogou.qadev.service.cynthia.bean.Script;
import com.sogou.qadev.service.cynthia.service.ScriptExecuteManager;

public class ScriptExecuteThread implements Runnable {

  @Override
  public void run() {
    while (true) {
      Interpreter interpreter = null;
      // 提取值,需要锁住对象
      synchronized (ScriptExecuteManager.allDeamonScript) {
        if (ScriptExecuteManager.allDeamonScript.size() == 0) {
          try {
            Thread.sleep(2000);
          } catch (InterruptedException e) {
            e.printStackTrace();
          }
          continue;
        }
        interpreter = ScriptExecuteManager.allDeamonScript.remove(0);
      }

      if (interpreter != null) {
        try {
          Script script = (Script) interpreter.get("script");
          if (script == null)
            continue;

          String content = script.getScript();
          if (content == null)
            continue;
          interpreter.eval(content);
        } catch (EvalError e) {
          e.printStackTrace();
        }
      }

    }

  }

}
TOP

Related Classes of com.sogou.qadev.service.cynthia.util.ScriptExecuteThread

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.