前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >专栏 >java Runtime.exec()执行shell/cmd命令:常见的几种陷阱与一种完善实现

java Runtime.exec()执行shell/cmd命令:常见的几种陷阱与一种完善实现

原创
作者头像
刘大猫
发布于 2024-11-17 10:41:05
发布于 2024-11-17 10:41:05
86501
代码可运行
举报
文章被收录于专栏:JAVA相关JAVA相关
运行总次数:1
代码可运行

@toc

背景说明

我们项目要java执行命令“dmidecode -s system-uuid”获取结果,然而碰到问题,当项目一直执行好久后,Runtime.getRuntime().exec()获取结果为空,但也不报错,重启项目就又可以了,所以猜测属于陷阱2,并进行记录。

Runtime.getRuntime().exec()执行JVM之外的程序:常见的几种陷阱

前言

日常java开发中,有时需要通过java运行其它应用功程序,比如shell命令等。jdk的Runtime类提供了这样的方法。首先来看Runtime类的文档, 从文档中可以看出,每个java程序只会有一个Runtime实例,显然这是一个单例模式。

代码语言:java
AI代码解释
复制
/**
 * Every Java application has a single instance of class
 * <code>Runtime</code> that allows the application to interface with
 * the environment in which the application is running. The current
 * runtime can be obtained from the <code>getRuntime</code> method.
 * <p>
 * An application cannot create its own instance of this class.
 */
 public class Runtime {
    private static Runtime currentRuntime = new Runtime();

    /**
     * Returns the runtime object associated with the current Java application.
     * Most of the methods of class <code>Runtime</code> are instance
     * methods and must be invoked with respect to the current runtime object.
     *
     * @return  the <code>Runtime</code> object associated with the current
     *          Java application.
     */
    public static Runtime getRuntime() {
        return currentRuntime;
    }

    /** Don't let anyone else instantiate this class */
    private Runtime() {}

    ......
}

要运行JVM中外的程序,Runtime类提供了如下方法,详细使用方法可参见源码注释

代码语言:java
AI代码解释
复制
public Process exec(String command) throws IOException

public Process exec(String cmdarray[]) throws IOException

public Process exec(String command, String[] envp) throws IOException

public Process exec(String command, String[] envp, File dir) throws IOException

public Process exec(String[] cmdarray, String[] envp) throws IOException

public Process exec(String[] cmdarray, String[] envp, File dir) throws IOException

通过这种方式运行外部程序,有几个陷阱需要注意,本文尝试总结常见的几个陷阱,并给出相应的解决方法。同时封装一种比较完善的工具类,用来运行外部应用,并提供超时功能。

Runtime.exec()常见的几种陷阱以及避免方法

陷阱1:IllegalThreadStateException

通过exec执行java命令为例子,最简单的方式如下。执行exec后,通过Process获取外部进程的返回值并输出。

代码语言:java
AI代码解释
复制
import java.io.IOException;

/**
 * Created by yangjinfeng02 on 2016/4/27.
 */
public class Main {

    public static void main(String[] args) {
        Runtime runtime = Runtime.getRuntime();
        try {
            Process process = runtime.exec("java");
            int exitVal = process.exitValue();
            System.out.println("process exit value is " + exitVal);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}

很遗憾的是,我们发现输出结果如下,抛出了IllegalThreadStateException异常

代码语言:java
AI代码解释
复制
Exception in thread "main" java.lang.IllegalThreadStateException: process has not exited
at java.lang.ProcessImpl.exitValue(ProcessImpl.java:443)
at com.baidu.ubqa.agent.runner.Main.main(Main.java:18)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:144)

为什么会抛出IllegalThreadStateException异常?

这是因为外部线程还没有结束,这个时候去获取退出码,exitValue()方法抛出了异常。看到这里读者可能会问,为什么这个方法不能阻塞到外部进程结束后再返回呢?确实如此,Process有一个waitFor()方法,就是这么做的,返回的也是退出码。因此,我们可以用waitFor()方法替换exitValue()方法。

陷阱2:Runtime.exec()可能hang住,甚至死锁

首先看下Process类的文档说明

代码语言:java
AI代码解释
复制
 * <p>By default, the created subprocess does not have its own terminal
 * or console.  All its standard I/O (i.e. stdin, stdout, stderr)
 * operations will be redirected to the parent process, where they can
 * be accessed via the streams obtained using the methods
 * {@link #getOutputStream()},
 * {@link #getInputStream()}, and
 * {@link #getErrorStream()}.
 * The parent process uses these streams to feed input to and get output
 * from the subprocess.  Because some native platforms only provide
 * limited buffer size for standard input and output streams, failure
 * to promptly write the input stream or read the output stream of
 * the subprocess may cause the subprocess to block, or even deadlock.

从这里可以看出,Runtime.exec()创建的子进程公用父进程的流,不同平台上,父进程的stream buffer可能被打满导致子进程阻塞,从而永远无法返回。

针对这种情况,我们只需要将子进程的stream重定向出来即可。

代码语言:java
AI代码解释
复制
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

/**
 * Created by yangjinfeng02 on 2016/4/27.
 */
public class Main {

    public static void main(String[] args) {
        List<String> strList = new ArrayList<>();
    Process process = null;
    InputStreamReader ir = null;
    LineNumberReader input = null;
    InputStreamReader errorStream = null;
    LineNumberReader errorReader = null;
    
    try {
        process = Runtime.getRuntime().exec(new String[]{"/bin/sh", "-c", shStr});
        
        // 处理标准输出流
        ir = new InputStreamReader(process.getInputStream());
        input = new LineNumberReader(ir);
        String line;
        while ((line = input.readLine()) != null){
            line = line.replaceAll(" ","");
            strList.add(line.toUpperCase());
        }
        
        // 处理错误输出流
        errorStream = new InputStreamReader(process.getErrorStream());
        errorReader = new LineNumberReader(errorStream);
        String errorLine;
        while ((errorLine = errorReader.readLine()) != null) {
            // 可以选择处理错误信息,或者直接打印出来
            System.err.println("Error output: " + errorLine);
        }
        
        // 等待命令执行结束
        process.waitFor();
        
    } catch (Exception e) {
        log.error("执行Shell命令失败", e);
    } finally {
        try {
            // 关闭输入流和错误流
            if (input != null) {
                input.close();
            }
            if (ir != null) {
                ir.close();
            }
            if (errorReader != null) {
                errorReader.close();
            }
            if (errorStream != null) {
                errorStream.close();
            }
            // 销毁进程
            if (process != null) {
                process.destroy();
            }
        } catch (IOException e) {
            log.error("关闭Shell流失败", e);
        }
    }
    return strList;
    }
}

陷阱3:不同平台上,命令的兼容性

如果要在windows平台上运行dir命令,如果直接指定命令参数为dir,会提示命令找不到。而且不同版本windows系统上,运行改命令的方式也不一样。对这宗情况,需要根据系统版本进行适当区分。

代码语言:java
AI代码解释
复制
String osName = System.getProperty("os.name" );
String[] cmd = new String[3];
if(osName.equals("Windows NT")) {
    cmd[0] = "cmd.exe" ;
    cmd[1] = "/C" ;
    cmd[2] = args[0];
} else if(osName.equals("Windows 95")) {
    cmd[0] = "command.com" ;
    cmd[1] = "/C" ;
    cmd[2] = args[0];
}  
Runtime rt = Runtime.getRuntime();
Process proc = rt.exec(cmd);

陷阱4:错把Runtime.exec()的command参数当做命令行

本质上来讲,Runtime.exec()的command参数只是一个可运行的命令或者脚本,并不等效于Shell解器或者Cmd.exe,如果你想进行输入输出重定向,pipeline等操作,则必须通过程序来实现。不能直接在command参数中做。例如,下面的例子

代码语言:java
AI代码解释
复制
Process process = runtime.exec("java -version > a.txt");

这样并不会产出a.txt文件。要达到这种目的,需通过编程手段实现,如下

代码语言:java
AI代码解释
复制
import java.io.BufferedReader;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;

/**
 * Created by yangjinfeng02 on 2016/4/27.
 */
class StreamGobbler extends Thread {
    InputStream is;
    String type;
    OutputStream os;

    StreamGobbler(InputStream is, String type) {
        this(is, type, null);
    }

    StreamGobbler(InputStream is, String type, OutputStream redirect) {
        this.is = is;
        this.type = type;
        this.os = redirect;
    }

    public void run() {
        try {
            PrintWriter pw = null;
            if (os != null)
                pw = new PrintWriter(os);

            InputStreamReader isr = new InputStreamReader(is);
            BufferedReader br = new BufferedReader(isr);
            String line;
            while ((line = br.readLine()) != null) {
                if (pw != null)
                    pw.println(line);
                System.out.println(type + ">" + line);
            }
            if (pw != null)
                pw.flush();
        } catch (IOException ioe) {
            ioe.printStackTrace();
        }
    }
}

public class Main {
    public static void main(String args[]) {
        try {
            FileOutputStream fos = new FileOutputStream("logs/a.log");
            Runtime rt = Runtime.getRuntime();
            Process proc = rt.exec("cmd.exe /C dir");

            // 重定向输出流和错误流
            StreamGobbler errorGobbler = new StreamGobbler(proc.getErrorStream(), "ERROR");
            StreamGobbler outputGobbler = new StreamGobbler(proc.getInputStream(), "OUTPUT", fos);

            errorGobbler.start();
            outputGobbler.start();
            int exitVal = proc.waitFor();
            System.out.println("ExitValue: " + exitVal);
            fos.flush();
            fos.close();
        } catch (Throwable t) {
            t.printStackTrace();
        }
    }
}

一个比较完善的工具类

下面提供一种比较完善的实现,提供了超时功能。

封装返回结果

代码语言:java
AI代码解释
复制
/**
* ExecuteResult.java
*/
import lombok.Data;
import lombok.ToString;

@Data
@ToString
public class ExecuteResult {
    private int exitCode;
    private String executeOut;

    public ExecuteResult(int exitCode, String executeOut) {
        this.exitCode = exitCode;
        this.executeOut = executeOut;
    }
}

对外接口

代码语言:java
AI代码解释
复制
/**
* LocalCommandExecutor.java
*/
public interface LocalCommandExecutor {
    ExecuteResult executeCommand(String command, long timeout);
}

StreamGobbler类,用来完成stream的管理

代码语言:java
AI代码解释
复制
/**
* StreamGobbler.java
*/
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class StreamGobbler extends Thread {
    private static Logger logger = LoggerFactory.getLogger(StreamGobbler.class);
    private InputStream inputStream;
    private String streamType;
    private StringBuilder buf;
    private volatile boolean isStopped = false;

    /**
     * @param inputStream the InputStream to be consumed
     * @param streamType  the stream type (should be OUTPUT or ERROR)
     */
    public StreamGobbler(final InputStream inputStream, final String streamType) {
        this.inputStream = inputStream;
        this.streamType = streamType;
        this.buf = new StringBuilder();
        this.isStopped = false;
    }

    /**
     * Consumes the output from the input stream and displays the lines consumed
     * if configured to do so.
     */
    @Override
    public void run() {
        try {
            // 默认编码为UTF-8,这里设置编码为GBK,因为WIN7的编码为GBK
            InputStreamReader inputStreamReader = new InputStreamReader(inputStream, "GBK");
            BufferedReader bufferedReader = new BufferedReader(inputStreamReader);
            String line = null;
            while ((line = bufferedReader.readLine()) != null) {
                this.buf.append(line + "\n");
            }
        } catch (IOException ex) {
            logger.trace("Failed to successfully consume and display the input stream of type " + streamType + ".", ex);
        } finally {
            this.isStopped = true;
            synchronized (this) {
                notify();
            }
        }
    }

    public String getContent() {
        if (!this.isStopped) {
            synchronized (this) {
                try {
                    wait();
                } catch (InterruptedException ignore) {
                    ignore.printStackTrace();
                }
            }
        }
        return this.buf.toString();
    }
}

实现类

通过SynchronousQueue队列保证只有一个线程在获取外部进程的退出码,由线程池提供超时功能。

代码语言:java
AI代码解释
复制
/**
* LocalCommandExecutorImpl.java
*/
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.Closeable;
import java.io.IOException;
import java.io.InputStream;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Future;
import java.util.concurrent.SynchronousQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;

public class LocalCommandExecutorImpl implements LocalCommandExecutor {

    static final Logger logger = LoggerFactory.getLogger(LocalCommandExecutorImpl.class);

    static ExecutorService pool = new ThreadPoolExecutor(0, Integer.MAX_VALUE, 3L, TimeUnit.SECONDS,
            new SynchronousQueue<Runnable>());

    public ExecuteResult executeCommand(String command, long timeout) {
        Process process = null;
        InputStream pIn = null;
        InputStream pErr = null;
        StreamGobbler outputGobbler = null;
        StreamGobbler errorGobbler = null;
        Future<Integer> executeFuture = null;
        try {
            logger.info(command.toString());
            process = Runtime.getRuntime().exec(command);
            final Process p = process;

            // close process's output stream.
            p.getOutputStream().close();

            pIn = process.getInputStream();
            outputGobbler = new StreamGobbler(pIn, "OUTPUT");
            outputGobbler.start();

            pErr = process.getErrorStream();
            errorGobbler = new StreamGobbler(pErr, "ERROR");
            errorGobbler.start();

            // create a Callable for the command's Process which can be called by an Executor
            Callable<Integer> call = new Callable<Integer>() {
                public Integer call() throws Exception {
                    p.waitFor();
                    return p.exitValue();
                }
            };

            // submit the command's call and get the result from a
            executeFuture = pool.submit(call);
            int exitCode = executeFuture.get(timeout, TimeUnit.MILLISECONDS);
            return new ExecuteResult(exitCode, outputGobbler.getContent());

        } catch (IOException ex) {
            String errorMessage = "The command [" + command + "] execute failed.";
            logger.error(errorMessage, ex);
            return new ExecuteResult(-1, null);
        } catch (TimeoutException ex) {
            String errorMessage = "The command [" + command + "] timed out.";
            logger.error(errorMessage, ex);
            return new ExecuteResult(-1, null);
        } catch (ExecutionException ex) {
            String errorMessage = "The command [" + command + "] did not complete due to an execution error.";
            logger.error(errorMessage, ex);
            return new ExecuteResult(-1, null);
        } catch (InterruptedException ex) {
            String errorMessage = "The command [" + command + "] did not complete due to an interrupted error.";
            logger.error(errorMessage, ex);
            return new ExecuteResult(-1, null);
        } finally {
            if (executeFuture != null) {
                try {
                    executeFuture.cancel(true);
                } catch (Exception ignore) {
                    ignore.printStackTrace();
                }
            }
            if (pIn != null) {
                this.closeQuietly(pIn);
                if (outputGobbler != null && !outputGobbler.isInterrupted()) {
                    outputGobbler.interrupt();
                }
            }
            if (pErr != null) {
                this.closeQuietly(pErr);
                if (errorGobbler != null && !errorGobbler.isInterrupted()) {
                    errorGobbler.interrupt();
                }
            }
            if (process != null) {
                process.destroy();
            }
        }
    }

    private void closeQuietly(Closeable c) {
        try {
            if (c != null) {
                c.close();
            }
        } catch (IOException e) {
            logger.error("exception", e);
        }
    }
}

原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。

如有侵权,请联系 cloudcommunity@tencent.com 删除。

原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。

如有侵权,请联系 cloudcommunity@tencent.com 删除。

评论
登录后参与评论
暂无评论
推荐阅读
快速搭建团队的GitLab
研发效能的其实端是代码仓的管理和统一维护,通过统一的私有化的Git托管服务实现代码的内部有限共享。代码仓在研发效能的提升中占据很重要的地位,这是DevOps工具链的起始点也是工程效能提升的一个重要环节。如果没有统一代码仓库我们也无法开始研发效能、质量效能、交付效能的衡量和提高。那么下面我们就开始讲解GitLab私有化仓库平台的搭建
Criss@陈磊
2019/09/25
7570
快速搭建团队的GitLab
Ubuntu离线安装软件包
a.当我们需要在多台电脑安装同一个软件,并且这个软件很大,下载需要很长时间时 b.需要安装软件的ubuntu不能上网
py3study
2020/01/20
5.6K0
ubuntu16.04安装qt5_qt安装哪些组件
Qt是一个跨平台的C++图形用户界面库,我们平时所说所使用的Qt,准确的来说是它的GUI编程部分。Qt提供给应用程序开发者建立图形用户界面所需要的功能,并且Qt很容易扩展。基本上,Qt和X Window上的Motif、Openwin、GTK等图形界面库和Windows平台上的MFC、OWL、VCl以及ATl是相同类型的东西。
全栈程序员站长
2022/11/04
1.4K0
ubuntu16.04安装qt5_qt安装哪些组件
更新Ubuntu软件源
原有的软件源的存储路径是/etc/apt/sources.list,文件内容如下。
全栈程序员站长
2022/09/15
1.5K0
更新Ubuntu软件源
rancher下的kubernetes之一:构建标准化vmware镜像
本文介绍了如何通过rancher部署kubernetes集群,包括创建vmware虚拟机、配置网络、安装和配置rancher、部署kubernetes等步骤。同时,还介绍了如何备份和恢复标准化的镜像文件,以便于快速部署和迁移。
程序员欣宸
2018/01/04
1.9K0
rancher下的kubernetes之一:构建标准化vmware镜像
docker ssh秘钥免密登录
有一台跳板机,已经实现了免密登录后端服务器。但是我写了一个django项目,它是运行在容器中的,也需要免密登录后端服务器。
py3study
2020/04/22
2.4K0
[ 利器篇 ] - Microsoft Surface Pro 系列安装 Ubuntu 16.04 系统
Microsoft Surface Pro 系列一直是平板+PC中的强者,刷新了针对PC的看法。这次由于项目的需求搭建测试环境,需要使用Ubuntu 16.04 系统,在Surface Pro 7 安装Ubuntu 16.04 进行开发体验。
程序手艺人
2020/09/15
3.9K0
[ 利器篇 ] -  Microsoft Surface Pro 系列安装 Ubuntu 16.04 系统
Ubuntu 16.04 几个国内更新源
sudo cp /etc/apt/sources.list /etc/apt/sources.list.old
用户8710806
2021/06/09
2.8K0
Ubuntu16.04安装及简单配置
sudo cp /etc/apt/sources.list  /etc/apt/sources.list.backup
foochane
2019/05/23
6630
Ubuntu16.04安装及简单配置
docker 运行Django项目
已经写好了一个Django项目,需要将这个项目用docker封装一个镜像,使用k8s发布!
py3study
2020/02/24
1.3K0
Ubuntu16安装Nvidia驱动(GTX1060显卡)
本篇概览 台式机是2018年购买的惠普暗隐精灵3代,显卡GTX1060,本文记录了此机器安装Ubuntu 16.04.7 LTS,再安装Nvidia驱动的过程; 另外还有一些避坑的小结,如果您遇到了类似问题可以拿来参考; 纯净Ubuntu系统 先安装Ubuntu16 LTS桌面版 U盘安装,我这里是惠普台式机,启动时出现惠普LOGO的时候,多次点击F10,进入bios,启动顺序选择U盘启动,然后在页面指导下顺利安装Ubuntu系统 需要注意的地方 网上很多安装文档中提到了要在BIOS设置中关闭secure
程序员欣宸
2021/12/07
9080
Ubuntu16安装Nvidia驱动(GTX1060显卡)
WIN10下创建Ubuntu18.04子系统及安装图形界面
控制面板——>程序——>程序和功能——>启用或关闭Windows功能——>适用于Linux的Windows子系统——>确定 (然后重启)
好派笔记
2021/09/17
3.1K0
ubuntu 14.04 16.04 18.04使用阿里源
版权声明:本博客上原创文章未经本人许可,不得用于商业用途及传统媒体。网络媒体转载请注明出处,否则属于侵权行为。 https://blog.csdn.net/bin_zhang1/article/details/81008645
用户1148525
2019/05/27
2.5K0
ubuntu16.04国内apt源以及官方源
替换写在/etc/apt目录的source.list文件 腾讯云 deb http://mirrors.tencentyun.com/ubuntu/ xenial main restricted un
禹都一只猫olei
2018/05/25
12.3K1
ubuntu 使用总结
清华源: https://mirror.tuna.tsinghua.edu.cn/help/ubuntu/
努力在北京混出人样
2019/02/18
7520
更换Ubuntu源为国内源的操作记录
我们都知道,Ubuntu的官方源对于国内用户来说是比较慢的,可以将它的源换成国内的源(比如阿里源),这样用起来就很快了。下面记录下更换操作: 首先了解下/etc/apt/sources.list.d文件 文件/etc/apt/sources.list是一个普通可编辑的文本文件,保存了ubuntu软件更新的源服务器的地址。 和sources.list功能一样的是/etc/apt/sources.list.d/*.list(*代表一个文件名,只能由字母、数字、下划线、英文句号组成), 该文件夹下的文件是第三方软
洗尽了浮华
2018/01/23
2.5K0
ubuntu的源
更换源的位置 /etc/apt/source.list 阿里云 # deb cdrom:[Ubuntu 16.04 LTS _Xenial Xerus_ - Release amd64 (20160420.1)]/ xenial main restricted deb-src http://archive.ubuntu.com/ubuntu xenial main restricted #Added by software-properties deb http://mirr
青木
2018/05/28
1K0
Ubuntu16桌面版编译和安装OpenCV4
本篇概览 这是一篇笔记,记录了纯净的Ubuntu16桌面版电脑上编译、安装、使用OpenCV4的全部过程,总的来说分为以下几部分: 安装必要软件,如cmake 下载OpenCV源码,包括opencv和opencv_contrib,并且解压、摆好位置 运行cmake-gui,在图形化页面上配置编译项 编译、安装 配置环境 验证 环境 环境信息如下: 操作系统:Ubuntu16.04桌面版 OpenCV:4.1.1 注意:本文全程使用非root账号操作 废话少说,直接在新装的Ubuntu16桌面版开始操作 换源
程序员欣宸
2021/12/07
9410
Ubuntu16桌面版编译和安装OpenCV4
ubuntu16.04 显卡驱动与cuda安装
摘要总结:本文主要介绍了在Ubuntu 16.04上配置Nvidia显卡驱动的方法,包括安装前的准备、下载驱动、安装驱动和配置环境。同时,还介绍了如何安装CUDA和Cudnn,以及如何在Ubuntu 16.04上安装Bazel构建C++项目。
ke1th
2018/01/02
2.4K0
ubuntu系统搭建饥荒服务器出现libcurl-gnutls.so.4: cannot open shared object file: No such file or directory怎么办
原因:饥荒是单核32位软件,只要使用64位的linux系统(常用ubuntu16.04和centos搭建),就需要安装一些32位的运行库软件
用户6948990
2025/04/03
1660
相关推荐
快速搭建团队的GitLab
更多 >
LV.0
这个人很懒,什么都没有留下~
目录
  • 背景说明
  • 前言
  • Runtime.exec()常见的几种陷阱以及避免方法
    • 陷阱1:IllegalThreadStateException
    • 陷阱2:Runtime.exec()可能hang住,甚至死锁
    • 陷阱3:不同平台上,命令的兼容性
    • 陷阱4:错把Runtime.exec()的command参数当做命令行
  • 一个比较完善的工具类
    • 封装返回结果
    • 对外接口
    • StreamGobbler类,用来完成stream的管理
    • 实现类
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档
本文部分代码块支持一键运行,欢迎体验
本文部分代码块支持一键运行,欢迎体验