You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
arthas/en/doc/async.html

55 lines
69 KiB
HTML

<!DOCTYPE html>
<html lang="en-US">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width,initial-scale=1">
3 years ago
<meta name="generator" content="VuePress 2.0.0-beta.51">
<style>
:root {
--c-bg: #fff;
}
html.dark {
--c-bg: #22272e;
}
html, body {
background-color: var(--c-bg);
}
</style>
<script>
const userMode = localStorage.getItem('vuepress-color-scheme');
const systemDarkMode = window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches;
if (userMode === 'dark' || (userMode !== 'light' && systemDarkMode)) {
document.documentElement.classList.toggle('dark', true);
}
</script>
3 years ago
<link rel="icon" href="/images/favicon.ico"><meta name="viewport" content="width=device-width, initial-scale=1.0"><meta property="og:title" content="Arthas"><meta property="og:image:alt" content="Alibaba Java Diagnostic Tool Arthas/Alibaba Java诊断利器Arthas - alibaba/arthas: Alibaba Java Diagnostic Tool Arthas/Alibaba Java诊断利器Arthas"><meta property="og:image" content="/images/arthas_mate_image.png"><meta property="og:description" content="Alibaba Java Diagnostic Tool Arthas/Alibaba Java诊断利器Arthas - alibaba/arthas: Alibaba Java Diagnostic Tool Arthas/Alibaba Java诊断利器Arthas"><meta property="og:image:width" content="1200"><meta property="og:image:height" content="600"><meta property="twitter:image:src" content="/images/arthas_mate_image.png"><meta property="twitter:image:alt" content="Alibaba Java Diagnostic Tool Arthas/Alibaba Java诊断利器Arthas - alibaba/arthas: Alibaba Java Diagnostic Tool Arthas/Alibaba Java诊断利器Arthas"><meta itemprop="name" content="Arthas"><meta itemprop="image" content="/images/arthas_mate_image.png"><meta itemprop="description" content="Alibaba Java Diagnostic Tool Arthas/Alibaba Java诊断利器Arthas - alibaba/arthas: Alibaba Java Diagnostic Tool Arthas/Alibaba Java诊断利器Arthas"><script>
var _hmt = _hmt || [];
(function() {
var hm = document.createElement("script");
hm.src = "https://hm.baidu.com/hm.js?d5c5e25b100f0eb51a4c35c8a86ea9b4";
var s = document.getElementsByTagName("script")[0];
s.parentNode.insertBefore(hm, s);
})();
2 years ago
</script><meta name="aes-config" content="pid=xux-opensource&user_type=101&uid=&username=&dim10=arthas"><script src="//g.alicdn.com/alilog/mlog/aplus_v2.js" id="beacon-aplus" exparams="clog=o&aplus&sidx=aplusSidx&ckx=aplusCkx"></script><script src="//g.alicdn.com/aes/??tracker/1.0.34/index.js,tracker-plugin-pv/2.4.5/index.js,tracker-plugin-event/1.2.5/index.js,tracker-plugin-jserror/1.0.13/index.js,tracker-plugin-api/1.1.14/index.js,tracker-plugin-perf/1.1.8/index.js,tracker-plugin-eventTiming/1.0.4/index.js"></script><title>Arthas Async Jobs | arthas</title><meta name="description" content="arthas user document">
2 years ago
<link rel="modulepreload" href="/assets/app.a26fb751.js"><link rel="modulepreload" href="/assets/async.html.31375d48.js"><link rel="modulepreload" href="/assets/async.html.a7feede3.js"><link rel="prefetch" href="/assets/index.html.84788405.js"><link rel="prefetch" href="/assets/index.html.806ea641.js"><link rel="prefetch" href="/assets/advanced-use.html.6a51f976.js"><link rel="prefetch" href="/assets/advice-class.html.224ee4a2.js"><link rel="prefetch" href="/assets/agent.html.7fb2e994.js"><link rel="prefetch" href="/assets/arthas-properties.html.0aa14eb6.js"><link rel="prefetch" href="/assets/arthas3.html.c547dc28.js"><link rel="prefetch" href="/assets/async.html.227408ac.js"><link rel="prefetch" href="/assets/auth.html.75b454c4.js"><link rel="prefetch" href="/assets/base64.html.cfb6f7e0.js"><link rel="prefetch" href="/assets/batch-support.html.6dd8c760.js"><link rel="prefetch" href="/assets/cat.html.6cdc566b.js"><link rel="prefetch" href="/assets/classloader.html.75c5e1ca.js"><link rel="prefetch" href="/assets/cls.html.2c126349.js"><link rel="prefetch" href="/assets/commands.html.23fd8667.js"><link rel="prefetch" href="/assets/contact-us.html.d767be56.js"><link rel="prefetch" href="/assets/dashboard.html.1dca4ac9.js"><link rel="prefetch" href="/assets/docker.html.9f25a18e.js"><link rel="prefetch" href="/assets/download.html.07b6d1c2.js"><link rel="prefetch" href="/assets/dump.html.213bb737.js"><link rel="prefetch" href="/assets/echo.html.8dc5f2cf.js"><link rel="prefetch" href="/assets/faq.html.bfa7b88d.js"><link rel="prefetch" href="/assets/getstatic.html.ea55aee5.js"><link rel="prefetch" href="/assets/grep.html.608be554.js"><link rel="prefetch" href="/assets/groovy.html.cb1faf0d.js"><link rel="prefetch" href="/assets/heapdump.html.d7c1054b.js"><link rel="prefetch" href="/assets/help.html.b816fbc7.js"><link rel="prefetch" href="/assets/history.html.585c7365.js"><link rel="prefetch" href="/assets/http-api.html.b873cd80.js"><link rel="prefetch" href="/assets/idea-plugin.html.ae8d6fdf.js"><link rel="prefetch" href="/assets/install-detail.html.a3dc2197.js"><link rel="prefetch" href="/assets/jad.html.d284d3c9.js"><link rel="prefetch" href="/assets/jfr.html.036cb593.js"><link rel="prefetch" href="/assets/jvm.html.9a5d399f.js"><link rel="prefetch" href="/assets/keymap.html.3df742d1.js"><link rel="prefetch" href="/assets/logger.html.0645797d.js"><link rel="prefetch" href="/assets/manual-install.html.0f1923ab.js"><link rel="prefetch" href="/assets/mbean.html.4ecaa7de.js"><link rel="prefetch" href="/assets/mc.html.03d8bb2f.js"><link rel="prefetch" href="/assets/memory.html.588ad57c.js"><link rel="prefetch" href="/assets/monitor.html.12cb2ce0.js"><link rel="prefetch" href="/assets/ognl.html.e34bbf20.js"><link rel="prefetch" href="/assets/options.html.668e000e.js"><link rel="prefetch" href="/assets/perfcounter.html.e5a4c6a0.js"><link rel="prefetch" href="/assets/profiler.html.2e0b667d.js"><link rel="prefetch" href="/assets/pwd.html.2d8e26f3.js"><link rel="prefetch" href="/assets/quick-start.html.66e6f859.js"><link rel="prefetch" href="/assets/quit.html.ee51efad.js"><link rel="prefetch" href="/assets/redefine.html.97540496.js"><link rel="prefetch" href="/assets/release-notes.html.a836d631.js"><link rel="prefetch" href="/assets/reset.html.e415a09c.js"><link rel="prefetch" href="/assets/retransform.html.7c2da729.js"><link rel="prefetch" href="/assets/save-log.html.676a8345.js"><link rel="prefetch" href="/assets/sc.html.7cc5c092.js"><link rel="prefetch" href="/assets/session.html.8e309fff.js"><link rel="prefetch" href="/assets/sm.html.488c49b6.js"><link rel="prefetch" href="/assets/spring-boot-starter.html.e9b63005.js"><link rel="prefetch" href="/assets/stack.html.347b1212.js"><link rel="prefetch" href="/assets/start-arthas.html.d9639d4c.js"><link rel="prefetch" href="/assets/stop.html.13a70a9e.js"><link rel="prefetch" href="/assets/sysenv.html.928f9596.js"><link rel="prefetch" href="/assets/sysprop.html.d7ae9a83.js"><link rel="prefetch" href="/assets/tee.html.8e722a1e.js"><link rel="prefetch" href="/assets/thread.html.5799728a.js
3 years ago
<link rel="stylesheet" href="/assets/style.da1934a3.css">
</head>
<body>
2 years ago
<div id="app"><!--[--><div class="theme-container"><!--[--><header class="navbar"><div class="toggle-sidebar-button" title="toggle sidebar" aria-expanded="false" role="button" tabindex="0"><div class="icon" aria-hidden="true"><span></span><span></span><span></span></div></div><span><a href="/en/" class="" data-v-61144abc><!----><span class="site-name can-hide" data-v-61144abc>arthas</span><span class="navbar-version" data-v-61144abc>v3.6.8</span></a></span><div class="navbar-items-wrapper" style=""><!--[--><!--]--><nav class="navbar-items can-hide"><!--[--><div class="navbar-item"><a href="/en/" class="" aria-label="HOME"><!--[--><!--]--> HOME <!--[--><!--]--></a></div><div class="navbar-item"><a class="external-link" href="/doc/arthas-tutorials.html?language=en&amp;id=arthas-basics" rel="noopener noreferrer" target="_blank" aria-label="ONLINE TUTORIALS"><!--[--><!--]--><span>ONLINE TUTORIALS</span><span><svg class="external-link-icon" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewbox="0 0 100 100" width="15" height="15"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path><polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg><span class="external-link-icon-sr-only">open in new window</span></span><!--[--><!--]--></a></div><div class="navbar-item"><a href="/en/doc" class="router-link-active" aria-label="DOCS"><!--[--><!--]--> DOCS <!--[--><!--]--></a></div><div class="navbar-item"><a href="/en/doc/commands.md" class="" aria-label="COMMANDS"><!--[--><!--]--> COMMANDS <!--[--><!--]--></a></div><div class="navbar-item"><a href="/en/doc/download.md" class="" aria-label="DOWNLOAD"><!--[--><!--]--> DOWNLOAD <!--[--><!--]--></a></div><div class="navbar-item"><div class="navbar-dropdown-wrapper"><button class="navbar-dropdown-title" type="button" aria-label="SOLUTIONS"><span class="title">SOLUTIONS</span><span class="arrow down"></span></button><button class="navbar-dropdown-title-mobile" type="button" aria-label="SOLUTIONS"><span class="title">SOLUTIONS</span><span class="right arrow"></span></button><ul style="display:none;" class="navbar-dropdown"><!--[--><li class="navbar-dropdown-item"><a class="external-link" href="https://cn.aliyun.com/product/aliware/mse?spm=arthas.topbar.0.0.0" rel="noopener noreferrer" target="_blank" aria-label="Microservice solutions"><!--[--><!--]--><span>Microservice solutions</span><span><svg class="external-link-icon" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewbox="0 0 100 100" width="15" height="15"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path><polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg><span class="external-link-icon-sr-only">open in new window</span></span><!--[--><!--]--></a></li><li class="navbar-dropdown-item"><a class="external-link" href="https://www.aliyun.com/aliware/txc?spm=arthas.topbar.0.0.0" rel="noopener noreferrer" target="_blank" aria-label="Distributed transaction solutions"><!--[--><!--]--><span>Distributed transaction solutions</span><span><svg class="external-link-icon" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewbox="0 0 100 100" width="15" height="15"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path><polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg><span class="external-link-icon-sr-only">open in new window</span></span><!--[--><!--]--></a></li><li class="navbar-dropdown-item"><a class="external-link" href="https://www.aliyun.com/product/aha
</code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div></div></div><p>By doing this, the current command is put to the background to run, you can continue to execute other commands in the console.</p><h2 id="_2-list-background-jobs" tabindex="-1"><a class="header-anchor" href="#_2-list-background-jobs" aria-hidden="true">#</a> 2. List background jobs</h2><p>If you want to list all background jobs, you can execute the <code>jobs</code> command and the results are as follows:</p><div class="language-bash ext-sh line-numbers-mode"><pre class="language-bash"><code>$ <span class="token function">jobs</span>
<span class="token punctuation">[</span><span class="token number">10</span><span class="token punctuation">]</span>*
3 years ago
Stopped <span class="token function">watch</span> com.taobao.container.Test <span class="token builtin class-name">test</span> <span class="token string">&quot;params[0].{? #this.name == null }&quot;</span> <span class="token parameter variable">-x</span> <span class="token number">2</span>
execution count <span class="token builtin class-name">:</span> <span class="token number">19</span>
start <span class="token function">time</span> <span class="token builtin class-name">:</span> Fri Sep <span class="token number">22</span> 09:59:55 CST <span class="token number">2017</span>
<span class="token function">timeout</span> <span class="token function">date</span> <span class="token builtin class-name">:</span> Sat Sep <span class="token number">23</span> 09:59:55 CST <span class="token number">2017</span>
session <span class="token builtin class-name">:</span> 3648e874-5e69-473f-9eed-7f89660b079b <span class="token punctuation">(</span>current<span class="token punctuation">)</span>
</code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><p>You can see that there is currently a background job executing:</p><ul><li>job id is 10, <code>*</code> indicates that this job is created by the current session.</li><li>status is <code>Stopped</code></li><li>execution count is the number of executions, which have been executed 19 times since the start.</li><li>timeout date: timeout timestamp, when the time exceeds this timestamp, the job will be automatically timeout and exit.</li></ul><h2 id="_3-suspend-and-cancel-job" tabindex="-1"><a class="header-anchor" href="#_3-suspend-and-cancel-job" aria-hidden="true">#</a> 3. Suspend and cancel job</h2><p>When the job is executing in the foreground, for example, directly executing the command <code>trace Test t</code>, or executing the background job command <code>trace Test t &amp;</code>, then putting the job back to the foreground via <code>fg</code> command, the console cannot continue to execute other command, but can receive and process the following keyboard events:</p><ul><li>ctrl + z: Suspends the job, the job status will change to <code>Stopped</code>, and the job can be restarted by <code>bg &lt;job-id&gt;</code> or <code>fg &lt;job-id&gt;</code></li><li>ctrl + c: Stops the job</li><li>ctrl + d: According to linux semantics this should lead to exit the terminal, right now Arthas has not implemented this yet, therefore simply ignore this keystroke.</li></ul><h2 id="_4-fg-bg-switch-the-job-from-the-foreground-to-the-background-and-vise-verse" tabindex="-1"><a class="header-anchor" href="#_4-fg-bg-switch-the-job-from-the-foreground-to-the-background-and-vise-verse" aria-hidden="true">#</a> 4. fg/bg, switch the job from the foreground to the background, and vise verse</h2><ul><li>When a job is executed in the background or in suspended status (use <code>ctrl + z</code> to suspend job), <code>fg &lt;job-id&gt;</code> can transfer the job to the foreground to continue to run.</li><li>When a job is in suspended status (use <code>ctrl + z</code> to suspend job), <code>bg &lt;job-id&gt;</code> can put the job to the background to continue to run.</li><li>A job created by other session can only be put to the foreground to run by using <code>fg</code> in the current session.</li></ul><h2 id="_5-redirect-the-output" tabindex="-1"><a class="header-anchor" href="#_5-redirect-the-output" aria-hidden="true">#</a> 5. Redirect the output</h2><p>The job output can be redirect to the specified file by <code>&gt;</code> or <code>&gt;&gt;</code>, and can be used together with <code>&amp;</code>. By doing this, you can achieve running commands asynchronously, for example:</p><div class="language-bash ext-sh line-numbers-mode"><pre class="language-bash"><code>$ trace Test t <span class="token operator">&gt;&gt;</span> test.out <span class="token operator">&amp;</span>
2 years ago
</code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div></div></div><p>At this time, the trace command will be executed in the background, and the result will be output to the <code>test.out</code> file under the <code>working directory</code> of the application. You can continue to execute other commands. And you can view the command execution result in the file. You can execute the <code>pwd</code> command to view the <code>working directory</code> of the current application.</p><div class="language-bash ext-sh line-numbers-mode"><pre class="language-bash"><code>$ <span class="token function">cat</span> test.out
</code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div></div></div><p>If no redirect file is specified, the result will be output to the <code>~/logs/arthas-cache/</code> directory, for example:</p><div class="language-bash ext-sh line-numbers-mode"><pre class="language-bash"><code>$ trace Test t <span class="token operator">&gt;&gt;</span> <span class="token operator">&amp;</span>
job <span class="token function">id</span> <span class="token builtin class-name">:</span> <span class="token number">2</span>
cache location <span class="token builtin class-name">:</span> /Users/admin/logs/arthas-cache/28198/2
</code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><p>At this time, the command will be executed asynchronously in the background, and the result will be asynchronously saved in the file (<code>~/logs/arthas-cache/${PID}/${JobId}</code>);</p><ul><li>At this time, the execution of the task is not affected by the session disconnection; the default timeout period of the task is 1 day, and the default timeout period can be modified through the global <code>options</code> command;</li><li>The result of this command will be output asynchronously to the file; at this time, regardless of whether <code>save-result</code> is true or not, the result will not be written asynchronously to <code>~/logs/arthas-cache/result.log</code>.</li></ul><h2 id="_6-stop-job" tabindex="-1"><a class="header-anchor" href="#_6-stop-job" aria-hidden="true">#</a> 6. Stop job</h2><p>If you want to stop background job, just <code>kill &lt;job-id&gt;</code>.</p><h2 id="_7-others" tabindex="-1"><a class="header-anchor" href="#_7-others" aria-hidden="true">#</a> 7. Others</h2><ul><li>Support up to 8 commands at the same time to redirect the output to the log files.</li><li>Do not open too many background jobs at the same time to avoid negative performance effect to the target JVM.</li><li>If you do not want to stop the Arthas service and continue to perform background tasks, you can exit the Arthas console by executing <code>quit</code> command (<code>stop</code> command will stop the Arthas service)</li></ul></div><!--[--><!--]--></div><footer class="page-meta right-menu-padding" data-v-fdd717e0><div class="meta-item edit-link"><a class="external-link meta-item-label" href="https://github.com/alibaba/arthas/edit/master/site/docs/en/doc/async.md" rel="noopener noreferrer" target="_blank" aria-label="Edit this page on GitHub"><!--[--><!--]--><span>Edit this page on GitHub</span><span><svg class="external-link-icon" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewbox="0 0 100 100" width="15" height="15"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path><polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg><span class="external-link-icon-sr-only">open in new window</span></span><!--[--><!--]--></a></div><div class="meta-item last-updated"><span class="meta-item-label">Last Updated: </span><!----></div><div class="meta-item contributors"><span class="meta-item-label">Contributors: </span><span class="meta-item-info"><!--[--><!--[--><span class="contributor" title="email: hengyunabc@gmail.com">hengyunabc</span><!--[-->, <!--]--><!--]--><!--[--><span class="contributor" title="email: 26602940+0xflotus@users.noreply.github.com">0xflotus</span><!--[-->, <!--]--><!--]--><!--[--><span class="contributor" title="email: arteevraina@gmail.com">Arteev Raina</span><!--[-->, <!--]--><!--]--><!--[--><span class="contributor" title="email: hollowman186@vip.qq.com">Hollow Man</span><!--[-->, <!--]--><!--]--><!--[--><span class="contributor" title="email: sergioescala@gmail.com">Sergio Escalante</span><!--[-->, <!--]--><!--]--><!--[--><span class="contributor" title="email: ian.luo@gmail.com">beiwei30</span><!--[-->, <!--]--><!--]--><!--[--><span class="contributor" title="email: 983433479@qq.com">汪吉</span><!----><!--]--><!--]--></span></div></footer><nav class="page-nav right-menu-padding" data-v-fdd717e0><p class="inner"><!----><span class="next"><a href="/en/doc/save-log.html" class="" aria-label="Log command outputs"><!--[--><!--]--> Log command outputs <!--[--><!--]--></a></span></p></nav><!--[--><!--]--></main><!--]--></div><!----><!--]--></div>
2 years ago
<script type="module" src="/assets/app.a26fb751.js" defer></script>
</body>
</html>