账号密码登录
微信安全登录
微信扫描二维码登录

登录后绑定QQ、微信即可实现信息互通

手机验证码登录
找回密码返回
邮箱找回 手机找回
注册账号返回
其他登录方式
分享
  • 收藏
    X
    java执行自定义脚本如何解决超时或死循环问题?
    31
    0

    自定义脚本代码并执行:

    可以自定义输入Groovy或者JS代码,然后执行。
    如何检测到这些自定义输入的脚本代码执行超时 或者是 死循环之类的。
    比如说我想要它执行5秒之后如果还没有结果,就返回给我某个信息,或抛出一个异常。

            //根据名称得到脚本引擎
            ScriptEngine engine = factory.getEngineByName("groovy");
            //Map inputData = (Map)((Map)input).get("data");
            Object inputData = input;
            String scriptCode = preprocessNode.getParameters();
    
            Map<String,Object> output=new HashMap<>();
            Bindings binding = engine.createBindings();
            binding.put("input",inputData);
            binding.put("output",output);
            try {
                engine.eval(scriptCode,binding);
                Invocable invokeEngine = (Invocable)engine;
                output  = (Map<String, Object>) invokeEngine.invokeFunction("executeMethod",null);
            } catch (ScriptException e) {
                logger.error("ScriptException : "+e.getMessage());
            } catch (NoSuchMethodException e) {
                logger.error("NoSuchMethodException : "+e.getMessage());
            }finally {
                countDownLatch.countDown();
            }
             return JSONObject.toJSON(output);
    0
    打赏
    收藏
    点击回答
    您的回答被采纳后将获得:提问者悬赏的 10 元积分
        全部回答
    • 0
    • 众羽 普通会员 1楼
      502 Bad Gateway

      502 Bad Gateway


      nginx
    更多回答
    网站公告
    扫一扫访问手机版
    • 回到顶部
    • 回到顶部