运行hbase脚本的java进程被阻止,无法杀死它

时间:2017-12-26 06:09:10

标签: java shell hbase

我想在java程序中运行hbase脚本,脚本是

balancer
exit

java代码是

<!-- language: java -->
public static void exec(String[] command) {
    try {
        ProcessBuilder builder = new ProcessBuilder(command);
        final Process process = builder.start();
        new Thread(new Runnable() {
            @Override
            public void run() {
                String line = null;
                BufferedReader in = new BufferedReader(
                        new InputStreamReader(process.getInputStream()));
                try {
                    while ((line = in.readLine()) != null) {
                    }
                } catch (IOException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                } finally {
                    try {
                        in.close();
                    } catch (IOException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    }
                }
            }
        }).start();
        new Thread(new Runnable() {
            @Override
            public void run() {
                String line = null;
                BufferedReader err = new BufferedReader(
                        new InputStreamReader(process.getErrorStream()));
                try {
                    while ((line = err.readLine()) != null) {
                    }
                } catch (IOException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                } finally {
                    try {
                        err.close();
                    } catch (IOException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    }
                }
            }
        }).start();
        process.waitFor();
    } catch (IOException e1) {
        // TODO Auto-generated catch block
        e1.printStackTrace();
    } catch (InterruptedException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}
public static void main(String[] args){
    exec( new String[]{HBASE_HOME + "/bin/hbase", "shell", 
            "./balancer.sql"});
}

我使用两个线程来处理errStream和inputStream以避免死锁,但是 该进程仍然被阻止,并且不能被命令&#34; kill -9&#34;杀死。我在日食中运行它,日食也被阻止了。

0 个答案:

没有答案