<!DOCTYPE html>
<!-- [if IE 8]><html class="no - js lt - ie9" lang="zh - CN" > <![endif] -->
<!-- [if gt IE 8]><! --> < html class = "no-js" lang = "zh-CN" > <!-- <![endif] -->
< head >
< meta charset = "utf-8" >
< meta name = "viewport" content = "width=device-width, initial-scale=1.0" >
< title > Arthas异步调用 — Arthas 3.3.6 文档< / title >
< link rel = "shortcut icon" href = "_static/favicon.ico" / >
< script type = "text/javascript" src = "_static/js/modernizr.min.js" > < / script >
< script type = "text/javascript" id = "documentation_options" data-url_root = "./" src = "_static/documentation_options.js" > < / script >
< script type = "text/javascript" src = "_static/jquery.js" > < / script >
< script type = "text/javascript" src = "_static/underscore.js" > < / script >
< script type = "text/javascript" src = "_static/doctools.js" > < / script >
< script type = "text/javascript" src = "_static/language_data.js" > < / script >
< script type = "text/javascript" src = "_static/translations.js" > < / script >
< script type = "text/javascript" src = "_static/js/theme.js" > < / script >
< link rel = "stylesheet" href = "_static/css/theme.css" type = "text/css" / >
< link rel = "stylesheet" href = "_static/pygments.css" type = "text/css" / >
< link rel = "stylesheet" href = "_static/overrides.css" type = "text/css" / >
< link rel = "index" title = "索引" href = "genindex.html" / >
< link rel = "search" title = "搜索" href = "search.html" / >
< link rel = "next" title = "执行结果存日志" href = "save-log.html" / >
< link rel = "prev" title = "以Java Agent的方式启动" href = "agent.html" / >
< script src = "_static/center_page.js" > < / script >
< link rel = "stylesheet" href = "https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.13.1/styles/github.min.css" >
< / head >
< body class = "wy-body-for-nav" >
< div class = "wy-grid-for-nav" >
< nav data-toggle = "wy-nav-shift" class = "wy-nav-side" >
< div class = "wy-side-scroll" >
< div class = "wy-side-nav-search" >
< a href = "index.html" class = "icon icon-home" > Arthas
< / a >
< div class = "version" >
3.3.6
< / div >
< div role = "search" >
< form id = "rtd-search-form" class = "wy-form" action = "search.html" method = "get" >
< input type = "text" name = "q" placeholder = "Search docs" / >
< input type = "hidden" name = "check_keywords" value = "yes" / >
< input type = "hidden" name = "area" value = "default" / >
< / form >
< / div >
< / div >
< div class = "wy-menu wy-menu-vertical" data-spy = "affix" role = "navigation" aria-label = "main navigation" >
< ul class = "current" >
< li class = "toctree-l1" > < a class = "reference external" href = "https://mp.weixin.qq.com/s/677GO-3kYx5ygG9rlOlfQg" > 招聘信息< / a > < / li >
< li class = "toctree-l1" > < a class = "reference external" href = "https://developer.aliyun.com/article/751641" > 技术征文< / a > < / li >
< li class = "toctree-l1" > < a class = "reference external" href = "https://alibaba.github.io/arthas/en/" > English Docs< / a > < / li >
< li class = "toctree-l1" > < a class = "reference external" href = "https://alibaba.github.io/arthas/arthas-tutorials?language=cn" > 在线教程(推荐)< / a > < / li >
< li class = "toctree-l1" > < a class = "reference internal" href = "install-detail.html" > 安装< / a > < / li >
< li class = "toctree-l1" > < a class = "reference internal" href = "download.html" > 下载< / a > < / li >
< li class = "toctree-l1" > < a class = "reference internal" href = "quick-start.html" > 快速入门< / a > < / li >
< li class = "toctree-l1 current" > < a class = "reference internal" href = "advanced-use.html" > 进阶使用< / a > < ul class = "current" >
< li class = "toctree-l2" > < a class = "reference internal" href = "advanced-use.html#id2" > 基础命令< / a > < / li >
< li class = "toctree-l2" > < a class = "reference internal" href = "advanced-use.html#jvm" > jvm相关< / a > < / li >
< li class = "toctree-l2" > < a class = "reference internal" href = "advanced-use.html#class-classloader" > class/classloader相关< / a > < / li >
< li class = "toctree-l2" > < a class = "reference internal" href = "advanced-use.html#monitor-watch-trace" > monitor/watch/trace相关< / a > < / li >
< li class = "toctree-l2" > < a class = "reference internal" href = "advanced-use.html#profiler" > profiler/火焰图< / a > < / li >
< li class = "toctree-l2" > < a class = "reference internal" href = "advanced-use.html#options" > options< / a > < / li >
< li class = "toctree-l2" > < a class = "reference internal" href = "advanced-use.html#id3" > 管道< / a > < / li >
< li class = "toctree-l2" > < a class = "reference internal" href = "advanced-use.html#id4" > 后台异步任务< / a > < / li >
< li class = "toctree-l2" > < a class = "reference internal" href = "advanced-use.html#web-console" > Web Console< / a > < / li >
< li class = "toctree-l2" > < a class = "reference internal" href = "advanced-use.html#java-agent" > 以java agent方式启动< / a > < / li >
< li class = "toctree-l2" > < a class = "reference internal" href = "advanced-use.html#id5" > 用户数据回报< / a > < / li >
< li class = "toctree-l2 current" > < a class = "reference internal" href = "advanced-use.html#id6" > 其他特性< / a > < ul class = "current" >
< li class = "toctree-l3 current" > < a class = "current reference internal" href = "#" > 异步命令支持< / a > < ul >
< li class = "toctree-l4" > < a class = "reference internal" href = "#id1" > 1. 使用& 在后台执行任务< / a > < / li >
< li class = "toctree-l4" > < a class = "reference internal" href = "#jobs" > 2. 通过jobs查看任务< / a > < / li >
< li class = "toctree-l4" > < a class = "reference internal" href = "#id2" > 3. 任务暂停和取消< / a > < / li >
< li class = "toctree-l4" > < a class = "reference internal" href = "#fgbg" > 4. fg、bg命令, 将命令转到前台、后台继续执行< / a > < / li >
< li class = "toctree-l4" > < a class = "reference internal" href = "#id3" > 5. 任务输出重定向< / a > < / li >
< li class = "toctree-l4" > < a class = "reference internal" href = "#id4" > 6. 停止命令< / a > < / li >
< li class = "toctree-l4" > < a class = "reference internal" href = "#id5" > 7. 其他< / a > < / li >
< / ul >
< / li >
< li class = "toctree-l3" > < a class = "reference internal" href = "save-log.html" > 执行结果存日志< / a > < / li >
< li class = "toctree-l3" > < a class = "reference internal" href = "batch-support.html" > 批处理的支持< / a > < / li >
< li class = "toctree-l3" > < a class = "reference external" href = "https://github.com/alibaba/arthas/issues/11" > ognl表达式的用法说明< / a > < / li >
< / ul >
< / li >
< / ul >
< / li >
< li class = "toctree-l1" > < a class = "reference internal" href = "commands.html" > 命令列表< / a > < / li >
< li class = "toctree-l1" > < a class = "reference internal" href = "web-console.html" > WebConsole< / a > < / li >
< li class = "toctree-l1" > < a class = "reference internal" href = "docker.html" > Docker< / a > < / li >
< li class = "toctree-l1" > < a class = "reference internal" href = "spring-boot-starter.html" > Arthas Spring Boot Starter< / a > < / li >
< li class = "toctree-l1" > < a class = "reference external" href = "https://github.com/alibaba/arthas/issues?q=label%3Auser-case" > 用户案例< / a > < / li >
< li class = "toctree-l1" > < a class = "reference external" href = "https://github.com/alibaba/arthas/issues?q=label%3Aquestion-answered" > 常见问题< / a > < / li >
< li class = "toctree-l1" > < a class = "reference external" href = "https://github.com/alibaba/arthas" > Fork me at GitHub< / a > < / li >
< li class = "toctree-l1" > < a class = "reference external" href = "https://github.com/alibaba/arthas/blob/master/CONTRIBUTING.md#" > 编译调试/参与贡献< / a > < / li >
< li class = "toctree-l1" > < a class = "reference external" href = "https://github.com/alibaba/arthas/releases" > Release Notes< / a > < / li >
< li class = "toctree-l1" > < a class = "reference internal" href = "contact-us.html" > QQ群/钉钉群< / a > < / li >
< li class = "toctree-l1" > < a class = "reference external" href = "https://arthas.gitee.io/" > 国内镜像站< / a > < / li >
< / ul >
< / div >
< / div >
< / nav >
< section data-toggle = "wy-nav-shift" class = "wy-nav-content-wrap" >
< nav class = "wy-nav-top" aria-label = "top navigation" >
< i data-toggle = "wy-nav-top" class = "fa fa-bars" > < / i >
< a href = "index.html" > Arthas< / a >
< / nav >
< div class = "wy-nav-content" >
< div class = "rst-content" >
< div role = "navigation" aria-label = "breadcrumbs navigation" >
< ul class = "wy-breadcrumbs" >
< li > < a href = "index.html" > Docs< / a > » < / li >
< li > < a href = "advanced-use.html" > 进阶使用< / a > » < / li >
< li > Arthas异步调用< / li >
< li class = "wy-breadcrumbs-aside" >
< a href = "https://github.com/alibaba/arthas/blob/master/site/src/site/sphinx/async.md" class = "fa fa-github" > Edit on GitHub< / a >
< / li >
< / ul >
< hr / >
< / div >
< div role = "main" class = "document" itemscope = "itemscope" itemtype = "http://schema.org/Article" >
< div itemprop = "articleBody" >
< div class = "section" id = "arthas" >
< h1 > Arthas异步调用< a class = "headerlink" href = "#arthas" title = "永久链接至标题" > ¶< / a > < / h1 >
< p > arthas中的异步调用, 使用了仿linux系统任务相关的命令。< a class = "reference external" href = "https://ehlxr.me/2017/01/18/Linux-%E4%B8%AD-fg%E3%80%81bg%E3%80%81jobs%E3%80%81-%E6%8C%87%E4%BB%A4/" > linux任务相关介绍< / a > 。< / p >
< div class = "section" id = "id1" >
< h2 > 1. 使用& 在后台执行任务< a class = "headerlink" href = "#id1" title = "永久链接至标题" > ¶< / a > < / h2 >
< p > 比如希望执行后台执行trace命令, 那么调用下面命令< / p >
< div class = "highlight-bash notranslate" > < div class = "highlight hljs" > < pre class = "bash" > trace Test t & < / pre > < / div >
< / div >
< p > 这时命令在后台执行, 可以在console中继续执行其他命令。< / p >
< / div >
< div class = "section" id = "jobs" >
< h2 > 2. 通过jobs查看任务< a class = "headerlink" href = "#jobs" title = "永久链接至标题" > ¶< / a > < / h2 >
< p > 如果希望查看当前有哪些arthas任务在执行, 可以执行jobs命令, 执行结果如下< / p >
< div class = "highlight-bash notranslate" > < div class = "highlight hljs" > < pre class = "bash" > $ jobs
[10]*
Stopped watch com.taobao.container.Test test " params[0].{? #this.name == null }" -x 2
execution count : 19
start time : Fri Sep 22 09:59:55 CST 2017
timeout date : Sat Sep 23 09:59:55 CST 2017
session : 3648e874-5e69-473f-9eed-7f89660b079b (current)< / pre > < / div >
< / div >
< p > 可以看到目前有一个后台任务在执行。< / p >
< ul class = "simple" >
< li > < p > job id是10, < code class = "docutils literal notranslate" > < span class = "pre" > *< / span > < / code > 表示此job是当前session创建< / p > < / li >
< li > < p > 状态是Stopped< / p > < / li >
< li > < p > execution count是执行次数, 从启动开始已经执行了19次< / p > < / li >
< li > < p > timeout date是超时的时间, 到这个时间, 任务将会自动超时退出< / p > < / li >
< / ul >
< / div >
< div class = "section" id = "id2" >
< h2 > 3. 任务暂停和取消< a class = "headerlink" href = "#id2" title = "永久链接至标题" > ¶< / a > < / h2 >
< p > 当任务正在前台执行,比如直接调用命令< code class = "docutils literal notranslate" > < span class = "pre" > trace< / span > < span class = "pre" > Test< / span > < span class = "pre" > t< / span > < / code > 或者调用后台执行命令< code class = "docutils literal notranslate" > < span class = "pre" > trace< / span > < span class = "pre" > Test< / span > < span class = "pre" > t< / span > < span class = "pre" > & < / span > < / code > 后又通过< code class = "docutils literal notranslate" > < span class = "pre" > fg< / span > < / code > 命令将任务转到前台。这时console中无法继续执行命令, 但是可以接收并处理以下事件: < / p >
< ul class = "simple" >
< li > < p > ‘ ctrl + z’ : 将任务暂停。通过< code class = "docutils literal notranslate" > < span class = "pre" > jbos< / span > < / code > 查看任务状态将会变为Stopped, 通过< code class = "docutils literal notranslate" > < span class = "pre" > bg< / span > < span class = "pre" > < job-id> < / span > < / code > 或者< code class = "docutils literal notranslate" > < span class = "pre" > fg< / span > < span class = "pre" > < job-id> < / span > < / code > 可让任务重新开始执行< / p > < / li >
< li > < p > ‘ ctrl + c’ : 停止任务< / p > < / li >
< li > < p > ‘ ctrl + d’ : 按照linux语义应当是退出终端, 目前arthas中是空实现, 不处理< / p > < / li >
< / ul >
< / div >
< div class = "section" id = "fgbg" >
< h2 > 4. fg、bg命令, 将命令转到前台、后台继续执行< a class = "headerlink" href = "#fgbg" title = "永久链接至标题" > ¶< / a > < / h2 >
< ul class = "simple" >
< li > < p > 任务在后台执行或者暂停状态(< code class = "docutils literal notranslate" > < span class = "pre" > ctrl< / span > < span class = "pre" > +< / span > < span class = "pre" > z< / span > < / code > 暂停任务)时,执行< code class = "docutils literal notranslate" > < span class = "pre" > fg< / span > < span class = "pre" > < job-id> < / span > < / code > 将可以把对应的任务转到前台继续执行。在前台执行时, 无法在console中执行其他命令< / p > < / li >
< li > < p > 当任务处于暂停状态时(< code class = "docutils literal notranslate" > < span class = "pre" > ctrl< / span > < span class = "pre" > +< / span > < span class = "pre" > z< / span > < / code > 暂停任务),执行< code class = "docutils literal notranslate" > < span class = "pre" > bg< / span > < span class = "pre" > < job-id> < / span > < / code > 将可以把对应的任务在后台继续执行< / p > < / li >
< li > < p > 非当前session创建的job, 只能由当前session fg到前台执行< / p > < / li >
< / ul >
< / div >
< div class = "section" id = "id3" >
< h2 > 5. 任务输出重定向< a class = "headerlink" href = "#id3" title = "永久链接至标题" > ¶< / a > < / h2 >
< p > 可通过< code class = "docutils literal notranslate" > < span class = "pre" > > < / span > < / code > 或者< code class = "docutils literal notranslate" > < span class = "pre" > > > < / span > < / code > 将任务输出结果输出到指定的文件中,可以和< code class = "docutils literal notranslate" > < span class = "pre" > & < / span > < / code > 一起使用, 实现arthas命令的异步调用。比如: < / p >
< div class = "highlight-bash notranslate" > < div class = "highlight hljs" > < pre class = "bash" > $ trace Test t > > test.out & < / pre > < / div >
< / div >
< p > 这时trace命令会在后台执行, 并且把结果输出到~/logs/arthas-cache/test.out。可继续执行其他命令。并可查看文件中的命令执行结果。< / p >
< p > 当连接到远程的arthas server时, 可能无法查看远程机器的文件, arthas同时支持了自动重定向到本地缓存路径。使用方法如下: < / p >
< div class = "highlight-bash notranslate" > < div class = "highlight hljs" > < pre class = "bash" > $ trace Test t > > &
job id : 2
cache location : /Users/gehui/logs/arthas-cache/28198/2< / pre > < / div >
< / div >
< p > 可以看到并没有指定重定向文件位置, arthas自动重定向到缓存中了, 执行命令后会输出job id和cache location。cache location就是重定向文件的路径, 在系统logs目录下, 路径包括pid和job id, 避免和其他任务冲突。命令输出结果到< code class = "docutils literal notranslate" > < span class = "pre" > /Users/gehui/logs/arthas-cache/28198/2< / span > < / code > 中, job id为2。< / p >
< / div >
< div class = "section" id = "id4" >
< h2 > 6. 停止命令< a class = "headerlink" href = "#id4" title = "永久链接至标题" > ¶< / a > < / h2 >
< p > 异步执行的命令, 如果希望停止, 可执行kill < job-id > < / p >
< / div >
< div class = "section" id = "id5" >
< h2 > 7. 其他< a class = "headerlink" href = "#id5" title = "永久链接至标题" > ¶< / a > < / h2 >
< ul class = "simple" >
< li > < p > 最多同时支持8个命令 使用重定向将结果写日志< / p > < / li >
< li > < p > 请勿同时开启过多的后台异步命令, 以免对目标JVM性能造成影响< / p > < / li >
< li > < p > 如果不想停止arthas, 继续执行后台任务, 可以执行 < code class = "docutils literal notranslate" > < span class = "pre" > quit< / span > < / code > 退出arthas控制台( < code class = "docutils literal notranslate" > < span class = "pre" > stop< / span > < / code > 会停止arthas 服务)< / p > < / li >
< / ul >
< / div >
< / div >
< / div >
< / div >
< footer >
< div class = "rst-footer-buttons" role = "navigation" aria-label = "footer navigation" >
< a href = "save-log.html" class = "btn btn-neutral float-right" title = "执行结果存日志" accesskey = "n" rel = "next" > Next < span class = "fa fa-arrow-circle-right" > < / span > < / a >
< a href = "agent.html" class = "btn btn-neutral float-left" title = "以Java Agent的方式启动" accesskey = "p" rel = "prev" > < span class = "fa fa-arrow-circle-left" > < / span > Previous< / a >
< / div >
< hr / >
< div role = "contentinfo" >
< p >
© Copyright 2018-2020, Alibaba Middleware Group, and contributors
< / p >
< / div >
Built with < a href = "http://sphinx-doc.org/" > Sphinx< / a > using a < a href = "https://github.com/rtfd/sphinx_rtd_theme" > theme< / a > provided by < a href = "https://readthedocs.org" > Read the Docs< / a > .
< / footer >
< / div >
< / div >
< / section >
< / div >
< script type = "text/javascript" >
jQuery(function () {
SphinxRtdTheme.Navigation.enable(true);
});
< / script >
< div class = "github-fork-ribbon-wrapper right" >
< div class = "github-fork-ribbon" >
< a href = "https://github.com/alibaba/arthas" target = "_blank" > Fork me at GitHub< / a >
< / div >
< / div >
< script type = "text/javascript" src = "_static/add_badges.js" > < / script >
< script src = "https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.13.1/highlight.min.js" > < / script >
< script src = "https://cdnjs.cloudflare.com/ajax/libs/highlightjs-line-numbers.js/2.5.0/highlightjs-line-numbers.min.js" > < / script >
< script >
document.querySelectorAll('div.hljs > pre').forEach(function(block) {
hljs.highlightBlock(block);
hljs.lineNumbersBlock(block);
});
< / script >
< script >
var _hmt = _hmt || [];
(function() {
var hm = document.createElement("script");
if (window.location.hostname == "arthas.gitee.io") {
hm.src = "https://hm.baidu.com/hm.js?ecc1b0d9aeb73da1671876133211d4d3";
} else { // https://alibaba.github.io/arthas/
hm.src = "https://hm.baidu.com/hm.js?d5c5e25b100f0eb51a4c35c8a86ea9b4";
}
var s = document.getElementsByTagName("script")[0];
s.parentNode.insertBefore(hm, s);
})();
< / script >
< / body >
< / html >