執行工具

public class RunUtil
extends Object implements IRunUtil

java.lang.Object
   ↳ com.android.tradefed.util.RunUtil


一系列執行作業的輔助方法。

摘要

欄位

public static final String INHERITIO_PREFIX

public static final String RUNNABLE_NOTIFIER_NAME

公用建構函式

RunUtil()

建立要使用的新 RunUtil 物件。

公用方法

void allowInterrupt(boolean allow)

允許/禁止在目前執行緒上中斷執行。

static IRunUtil getDefault()

取得預設 RunUtil 物件的參照。

void interrupt(Thread thread, String message, ErrorIdentifier errorId)

中斷指定執行緒進行中/即將執行的執行作業。

void interrupt(Thread thread, String message)

中斷指定執行緒進行中/即將執行的執行作業。

boolean isInterruptAllowed()

指定 RunUtil 的中斷狀態。

Process runCmdInBackground(Redirect redirect, command)

替代的 runCmdInBackground(String) 方法,可接受 ERROR(/List) 形式中的指令引數。

Process runCmdInBackground( command)

替代的 runCmdInBackground(String) 方法,可接受 ERROR(/List) 形式中的指令引數。

Process runCmdInBackground( command, OutputStream output)

使用 ERROR(/OutputStream) 執行指令,記錄指令輸出內容。

Process runCmdInBackground(String... command)

以非同步方式執行系統指令的輔助方法。

Process runCmdInBackground(Redirect redirect, String... command)

以非同步方式執行系統指令的輔助方法。

boolean runEscalatingTimedRetry(long opTimeout, long initialPollInterval, long maxPollInterval, long maxTime, IRunUtil.IRunnableResult runnable)

多次封鎖並執行一項作業,直到成功為止。

boolean runFixedTimedRetry(long opTimeout, long pollInterval, long maxTime, IRunUtil.IRunnableResult runnable)

多次封鎖並執行一項作業,直到成功為止。

boolean runFixedTimedRetryWithOutputMonitor(long opTimeout, long idleOutputTimeout, long pollInterval, long maxTime, IRunUtil.IRunnableResult runnable)

多次封鎖並執行一項作業,直到成功為止。

CommandStatus runTimed(long timeout, IRunUtil.IRunnableResult runnable, boolean logErrors)

封鎖並執行作業,如果作業時間超過指定時間,就會取消作業。

CommandResult runTimedCmd(long timeout, OutputStream stdout, OutputStream stderr, String... command)

執行系統指令的輔助方法,如果執行時間超過指定時間,則會取消,並將輸出內容重新導向至檔案 (如有指定)。

CommandResult runTimedCmd(long timeout, String... command)

輔助方法執行系統指令,並在所需時間超過指定時間時取消。

CommandResult runTimedCmdRetry(long timeout, long retryInterval, int attempts, String... command)

輔助方法執行系統指令,並在所需時間超過指定時間時取消。

CommandResult runTimedCmdRetryWithOutputMonitor(long timeout, long idleOutputTimeout, long retryInterval, int attempts, String... command)

輔助方法執行系統指令,並在所需時間超過指定時間時取消。

CommandResult runTimedCmdSilently(long timeout, String... command)

輔助方法執行系統指令,並在所需時間超過指定時間時取消。

CommandResult runTimedCmdSilentlyRetry(long timeout, long retryInterval, int attempts, String... command)

輔助方法執行系統指令,並在所需時間超過指定時間時取消。

CommandResult runTimedCmdWithInput(long timeout, String input, File stdoutFile, File stderrFile, String... command)

執行系統指令的輔助方法,如果執行時間超過指定時間,則會取消,並將輸出內容重新導向至檔案 (如有指定)。

CommandResult runTimedCmdWithInput(long timeout, String input, String... command)

輔助方法可執行需要 stdin 輸入的系統指令,並在所需時間超過指定時間時取消。

CommandResult runTimedCmdWithInput(long timeout, String input, command)

輔助方法可執行需要 stdin 輸入的系統指令,並在所需時間超過指定時間時取消。

CommandResult runTimedCmdWithInputRedirect(long timeout, File inputRedirect, String... command)

輔助方法執行系統指令,需要從檔案重新導向 Stdin,並在所需時間超過指定時間時取消作業。

CommandResult runTimedCmdWithOutputMonitor(long timeout, long idleOutputTimeout, OutputStream stdout, OutputStream stderr, String... command)

執行系統指令的輔助方法,如果執行時間超過指定時間,則會取消,並將輸出內容重新導向至檔案 (如有指定)。

CommandResult runTimedCmdWithOutputMonitor(long timeout, long idleOutputTimeout, String... command)

輔助方法執行系統指令,並在所需時間超過指定時間時取消。

CommandResult runTimedCmdWithOutputMonitor(long timeout, long idleOutputTimeout, OutputStream stdout, OutputStream stderr, ICacheClient cacheClient, String... command)

透過快取執行系統指令的輔助方法。

boolean runTimedRetry(long opTimeout, long pollInterval, int attempts, IRunUtil.IRunnableResult runnable)

多次封鎖並執行一項作業,直到成功為止。

boolean runTimedRetryWithOutputMonitor(long opTimeout, long idleOutputTimeout, long pollInterval, int attempts, IRunUtil.IRunnableResult runnable)

多次封鎖並執行一項作業,直到成功為止。

CommandStatus runTimedWithOutputMonitor(long timeout, long idleOutputTimeout, IRunUtil.IRunnableResult runnable, boolean logErrors)

封鎖並執行作業,如果作業時間超過指定時間,就會取消作業。

void setEnvVariable(String name, String value)

設定執行系統指令時要使用的環境變數。

void setEnvVariablePriority(IRunUtil.EnvPriority priority)

決定建立程序時,取消設定環境變數的優先順序是否高於設定值。

void setInterruptibleInFuture(Thread thread, long timeMs)

設為等待一段時間後可中斷。

void setLinuxInterruptProcess(boolean interrupt)

允許在達到逾時時,在透過 #runTimed 方法執行的程序中使用 Linux「kill」中斷。

void setRedirectStderrToStdout(boolean redirect)

設定標準錯誤串流,讓系統在執行系統指令時重新導向至標準輸出串流。

void setWorkingDir(File dir)

設定系統指令的工作目錄。

void sleep(long time)

輔助方法:在指定時間入睡,忽略任何例外狀況。

void unsetEnvVariable(String key)

取消設定環境變數,如此一來,系統指令就會在沒有這個環境變數的情況下執行。 環境變數可能會繼承父項程序,因此我們需要從 ProcessBuilder.environment() 中刪除環境變數

欄位

INHERITIO_PREFIX

public static final String INHERITIO_PREFIX

RUNNABLE_NOTIFIER_NAME

public static final String RUNNABLE_NOTIFIER_NAME

公用建構函式

執行工具

public RunUtil ()

建立要使用的新 RunUtil 物件。

公用方法

允許中斷

public void allowInterrupt (boolean allow)

允許/禁止在目前執行緒上執行中斷。如果允許,則可透過 interrupt(Thread, String) 方法,從其他執行緒中斷目前執行緒的作業。

參數
allow boolean:是否允許目前執行緒上的執行作業中斷。

getDefault

public static IRunUtil getDefault ()

取得預設 RunUtil 物件的參照。

這對於想要在不自訂的情況下使用 IRunUtil 的呼叫端非常有幫助。建議需要自訂 IRunUtil 執行個體的呼叫端 (亦即呼叫 setEnvVariable(String, String)setWorkingDir(File) 自行建立副本)。

傳回
IRunUtil

中斷

public void interrupt (Thread thread, 
                String message, 
                ErrorIdentifier errorId)

中斷指定執行緒進行中/即將執行的執行作業。指定執行緒上的執行作業會擲回 RunInterruptedException

參數
message StringRunInterruptedException 的訊息。

errorId ErrorIdentifier:代表中斷原因 (如果已知)。

中斷

public void interrupt (Thread thread, 
                String message)

中斷指定執行緒進行中/即將執行的執行作業。指定執行緒上的執行作業會擲回 RunInterruptedException

參數
message StringRunInterruptedException 的訊息。

isInterruptAllowed 是否允許

public boolean isInterruptAllowed ()

指定 RunUtil 的中斷狀態。

傳回
boolean 如果執行可以中斷,傳回 true,否則傳回 false。

runCmdInBackground

public Process runCmdInBackground (Redirect redirect, 
                 command)

runCmdInBackground(String) 替代方法,可接受 ERROR(/List) 形式中的指令引數。

參數
redirect Redirect:要套用至 ProcessBuilderERROR(/Redirect)

command :包含指定系統指令和 exec 的選用引數的 ERROR(/List)

傳回
Process 已執行指令的 Process

runCmdInBackground

public Process runCmdInBackground ( command)

runCmdInBackground(String) 替代方法,可接受 ERROR(/List) 形式中的指令引數。

參數
command :包含指定系統指令和 exec 的選用引數的 ERROR(/List)

傳回
Process 已執行指令的 Process

runCmdInBackground

public Process runCmdInBackground ( command, 
                OutputStream output)

使用 ERROR(/OutputStream) 執行指令,記錄指令輸出內容。Stdout 和 stderr 會合併在一起。

參數
command :要執行的指令

output OutputStream:用於儲存輸出內容的 OutputStream

傳回
Process 執行指令的 Process

runCmdInBackground

public Process runCmdInBackground (String... command)

以非同步方式執行系統指令的輔助方法。

會在啟動指令後立即傳回。

參數
command String:指定的系統指令和 exec 的選用引數

傳回
Process 已執行指令的 Process

runCmdInBackground

public Process runCmdInBackground (Redirect redirect, 
                String... command)

以非同步方式執行系統指令的輔助方法。

會在啟動指令後立即傳回。

參數
redirect Redirect:要套用至 ProcessBuilderERROR(/Redirect)

command String:指定的系統指令和 exec 的選用引數

傳回
Process 已執行指令的 Process

runEscalatingTimed 重試

public boolean runEscalatingTimedRetry (long opTimeout, 
                long initialPollInterval, 
                long maxPollInterval, 
                long maxTime, 
                IRunUtil.IRunnableResult runnable)

多次封鎖並執行作業,直到成功為止。

每次嘗試執行作業之間的等待時間會指數增加。這個 ID 可用於執行輪詢伺服器等作業,以便在服務暫時無法使用時提供復原時間。

參數
opTimeout long:單一作業嘗試的等待時間上限 (毫秒)

initialPollInterval long:嘗試執行兩次作業時,等待的初始時間

maxPollInterval long:嘗試作業之間等待的時間上限

maxTime long:嘗試執行作業的總時間約略值

runnable IRunUtil.IRunnableResult:要執行的 IRunUtil.IRunnableResult

傳回
boolean 如果作業在 maxTime 到期前成功完成,則為 true

runFixedTimed 重試

public boolean runFixedTimedRetry (long opTimeout, 
                long pollInterval, 
                long maxTime, 
                IRunUtil.IRunnableResult runnable)

多次封鎖並執行一項作業,直到成功為止。

參數
opTimeout long:單一作業嘗試的等待時間上限 (毫秒)

pollInterval long:嘗試執行兩次作業時,等待的初始時間

maxTime long:嘗試執行作業的總時間約略值

runnable IRunUtil.IRunnableResult:要執行的 IRunUtil.IRunnableResult

傳回
boolean 如果作業在 maxTime 到期前成功完成,則為 true

runFixedTimed 重試 WithOutputMonitor

public boolean runFixedTimedRetryWithOutputMonitor (long opTimeout, 
                long idleOutputTimeout, 
                long pollInterval, 
                long maxTime, 
                IRunUtil.IRunnableResult runnable)

多次封鎖並執行一項作業,直到成功為止。還會監控活動的輸出串流,如果在指定時間未觀察到串流活動時取消,則取消串流。如果閒置輸出逾時設為零,就不會發生串流監控事件。

參數
opTimeout long:單一作業嘗試的等待時間上限 (毫秒)

idleOutputTimeout long:輸出串流的輸出內容最長 (以毫秒為單位)

pollInterval long:嘗試執行兩次作業時,等待的初始時間

maxTime long:嘗試執行作業的總時間約略值

runnable IRunUtil.IRunnableResult:要執行的 IRunUtil.IRunnableResult

傳回
boolean 如果作業在 maxTime 到期前成功完成,則為 true

執行時間

public CommandStatus runTimed (long timeout, 
                IRunUtil.IRunnableResult runnable, 
                boolean logErrors)

封鎖並執行作業,如果作業時間超過指定時間,就會取消作業。

參數
timeout long:等待時間上限 (毫秒)

runnable IRunUtil.IRunnableResult:要執行的 IRunUtil.IRunnableResult

logErrors boolean:在例外狀況上記錄錯誤。

傳回
CommandStatus CommandStatus 作業的結果。

runTimedCmd

public CommandResult runTimedCmd (long timeout, 
                OutputStream stdout, 
                OutputStream stderr, 
                String... command)

執行系統指令的輔助方法,如果執行時間超過指定時間,則會取消;如果有指定,會將輸出內容重新導向至檔案。透過這種方式提供 ERROR(/OutputStream) 時,它們會在函式結尾保持開啟。

參數
timeout long:逾時等候時間上限 (毫秒)。0 代表沒有逾時。

stdout OutputStream:要重新導向 std 輸出內容的 ERROR(/OutputStream)。可以是空值。

stderr OutputStreamERROR(/OutputStream),其中會重新導向錯誤輸出內容。可以是空值。

command String:指定的系統指令和 exec 的選用引數

傳回
CommandResult 含有執行指令執行結果的 CommandResult

runTimedCmd

public CommandResult runTimedCmd (long timeout, 
                String... command)

輔助方法執行系統指令,並在所需時間超過指定時間時取消。

參數
timeout long:等待時間上限 (毫秒)。0 代表沒有逾時。

command String:指定的系統指令和 exec 的選用引數

傳回
CommandResult 含有執行指令執行結果的 CommandResult

runTimedCmd 重試

public CommandResult runTimedCmdRetry (long timeout, 
                long retryInterval, 
                int attempts, 
                String... command)

輔助方法執行系統指令,並在所需時間超過指定時間時取消。

參數
timeout long:每次嘗試時等待的時間上限 (毫秒)

retryInterval long:每次重試指令前的等待時間

attempts int:嘗試次數上限

command String:指定的系統指令和 exec 的選用引數

傳回
CommandResult 含有執行指令執行結果的 CommandResult

runTimedCmd 重試 WithOutputMonitor

public CommandResult runTimedCmdRetryWithOutputMonitor (long timeout, 
                long idleOutputTimeout, 
                long retryInterval, 
                int attempts, 
                String... command)

輔助方法執行系統指令,並在所需時間超過指定時間時取消。一併監控活動的輸出串流,如果在指定時間未觀察到串流活動時取消,則取消串流。如果閒置輸出逾時設為零,就不會發生串流監控的情形。

參數
timeout long:每次嘗試時等待的時間上限 (毫秒)

idleOutputTimeout long:輸出串流的輸出內容最長 (以毫秒為單位)

retryInterval long:每次重試指令前的等待時間

attempts int:嘗試次數上限

command String:指定的系統指令和 exec 的選用引數

傳回
CommandResult 含有執行指令執行結果的 CommandResult

runTimedCmdSilently

public CommandResult runTimedCmdSilently (long timeout, 
                String... command)

輔助方法執行系統指令,並在所需時間超過指定時間時取消。與 runTimedCmd(long, String) 類似,但不會記錄例外狀況上的任何錯誤。

參數
timeout long:等待時間上限 (毫秒)

command String:指定的系統指令和 exec 的選用引數

傳回
CommandResult 含有執行指令執行結果的 CommandResult

runTimedCmdSilently 重試

public CommandResult runTimedCmdSilentlyRetry (long timeout, 
                long retryInterval, 
                int attempts, 
                String... command)

輔助方法執行系統指令,並在所需時間超過指定時間時取消。與 runTimedCmdRetry(long, long, int, String[]) 類似,但不會記錄例外狀況上的任何錯誤。

參數
timeout long:等待時間上限 (毫秒)

retryInterval long:每次重試指令前的等待時間

attempts int:嘗試次數上限

command String:指定的系統指令和 exec 的選用引數

傳回
CommandResult 含有執行指令執行結果的 CommandResult

runTimedCmdWithInput

public CommandResult runTimedCmdWithInput (long timeout, 
                String input, 
                File stdoutFile, 
                File stderrFile, 
                String... command)

執行系統指令的輔助方法,如果執行時間超過指定時間,則會取消;如果有指定,會將輸出內容重新導向至檔案。

參數
timeout long:逾時等候時間上限 (毫秒)。0 代表沒有逾時。

input String:要傳遞給處理的 stdin 輸入內容

stdoutFile File:要重新導向 std 輸出內容的 ERROR(/File)。可以是空值。

stderrFile FileERROR(/File),其中會重新導向錯誤輸出內容。可以是空值。

command String:指定的系統指令和 exec 的選用引數

傳回
CommandResult 含有執行指令執行結果的 CommandResult

runTimedCmdWithInput

public CommandResult runTimedCmdWithInput (long timeout, 
                String input, 
                String... command)

輔助方法可執行需要 stdin 輸入的系統指令,並在所需時間超過指定時間時取消。

參數
timeout long:等待時間上限 (毫秒)

input String:要傳遞給處理的 stdin 輸入內容

command String:指定的系統指令和 exec 的選用引數

傳回
CommandResult 含有執行指令執行結果的 CommandResult

runTimedCmdWithInput

public CommandResult runTimedCmdWithInput (long timeout, 
                String input, 
                 command)

輔助方法可執行需要 stdin 輸入的系統指令,並在所需時間超過指定時間時取消。

參數
timeout long:等待時間上限 (毫秒)

input String:要傳遞給處理的 stdin 輸入內容

command ERROR(/List),包含系統指令和 exec 的選用引數

傳回
CommandResult 含有執行指令執行結果的 CommandResult

runTimedCmdWithInputRedirect

public CommandResult runTimedCmdWithInputRedirect (long timeout, 
                File inputRedirect, 
                String... command)

輔助方法可執行需要從檔案重新導向 Stdin 的系統指令,並在所需時間超過指定時間時取消。

參數
timeout long:等待時間上限 (毫秒)

inputRedirect File:使用 ProcessBuilder.redirectInput() 重新導向至標準輸入的 ERROR(/File)。如果值為空值,系統不會重新導向 stdin。

command String:指定的系統指令和 exec 的選用引數

傳回
CommandResult 含有執行指令執行結果的 CommandResult

runTimedCmdWithOutputMonitor

public CommandResult runTimedCmdWithOutputMonitor (long timeout, 
                long idleOutputTimeout, 
                OutputStream stdout, 
                OutputStream stderr, 
                String... command)

執行系統指令的輔助方法,如果執行時間超過指定時間,則會取消;如果有指定,會將輸出內容重新導向至檔案。透過這種方式提供 ERROR(/OutputStream) 時,它們會在函式結尾保持開啟。

參數
timeout long:逾時等候時間上限 (毫秒)。0 代表沒有逾時。

idleOutputTimeout long:輸出串流的輸出內容最長 (以毫秒為單位)

stdout OutputStream:要重新導向 std 輸出內容的 ERROR(/OutputStream)。可以是空值。

stderr OutputStreamERROR(/OutputStream),其中會重新導向錯誤輸出內容。可以是空值。

command String:指定的系統指令和 exec 的選用引數

傳回
CommandResult 含有執行指令執行結果的 CommandResult

runTimedCmdWithOutputMonitor

public CommandResult runTimedCmdWithOutputMonitor (long timeout, 
                long idleOutputTimeout, 
                String... command)

輔助方法執行系統指令,並在所需時間超過指定時間時取消。一併監控活動的輸出串流,如果在指定時間未觀察到串流活動時取消,則取消串流。如果閒置輸出逾時設為零,就不會發生串流監控的情形。

參數
timeout long:等待時間上限 (毫秒)。0 代表沒有逾時。

idleOutputTimeout long:輸出串流的輸出內容最長 (以毫秒為單位)

command String:指定的系統指令和 exec 的選用引數

傳回
CommandResult 含有執行指令執行結果的 CommandResult

runTimedCmdWithOutputMonitor

public CommandResult runTimedCmdWithOutputMonitor (long timeout, 
                long idleOutputTimeout, 
                OutputStream stdout, 
                OutputStream stderr, 
                ICacheClient cacheClient, 
                String... command)

透過快取執行系統指令的輔助方法。

如果指定 cacheClient,系統就會啟用快取。如果有可用的快取,系統會傳回快取結果。否則,系統會使用 runTimedCmdWithOutputMonitor(long, long, OutputStream, OutputStream, String) 執行指令,並上傳結果以供快取。

參數
timeout long:逾時等候時間上限 (毫秒)。0 代表沒有逾時。

idleOutputTimeout long:輸出串流的輸出內容最長 (以毫秒為單位)。

stdout OutputStream:要重新導向 std 輸出內容的 ERROR(/OutputStream)。可以是空值。

stderr OutputStreamERROR(/OutputStream),其中會重新導向錯誤輸出內容。可以是空值。

cacheClient ICacheClient:用於處理快取的 ICacheClient 例項。

command String:指定的系統指令和 exec 的選用引數。

傳回
CommandResult 含有指令執行結果的 CommandResult

runTimed 重試

public boolean runTimedRetry (long opTimeout, 
                long pollInterval, 
                int attempts, 
                IRunUtil.IRunnableResult runnable)

多次封鎖並執行一項作業,直到成功為止。

參數
opTimeout long:嘗試一次作業後等待的時間上限 (毫秒)

pollInterval long:每次重試指令前的等待時間

attempts int:嘗試次數上限

runnable IRunUtil.IRunnableResult:要執行的 IRunUtil.IRunnableResult

傳回
boolean 如果作業在嘗試前已順利完成,則為 true

runTimed 重試 WithOutputMonitor

public boolean runTimedRetryWithOutputMonitor (long opTimeout, 
                long idleOutputTimeout, 
                long pollInterval, 
                int attempts, 
                IRunUtil.IRunnableResult runnable)

多次封鎖並執行一項作業,直到成功為止。還會監控活動的輸出串流,如果在指定時間未觀察到串流活動時取消,則取消串流。如果閒置輸出逾時設為零,就不會發生串流監控事件。

參數
opTimeout long:嘗試一次作業後等待的時間上限 (毫秒)

idleOutputTimeout long:輸出串流的輸出內容最長 (以毫秒為單位)

pollInterval long:每次重試指令前的等待時間

attempts int:嘗試次數上限

runnable IRunUtil.IRunnableResult:要執行的 IRunUtil.IRunnableResult

傳回
boolean 如果作業在嘗試前已順利完成,則為 true

runTimedWithOutputMonitor

public CommandStatus runTimedWithOutputMonitor (long timeout, 
                long idleOutputTimeout, 
                IRunUtil.IRunnableResult runnable, 
                boolean logErrors)

封鎖並執行作業,如果作業時間超過指定時間,就會取消作業。也會監控活動的輸出串流,如果在指定時間未觀察到串流活動時取消,則取消串流。如果閒置輸出逾時設為零,就不會發生串流監控事件。

參數
timeout long:等待時間上限 (毫秒)

idleOutputTimeout long:輸出串流的輸出內容最長 (以毫秒為單位)

runnable IRunUtil.IRunnableResult:要執行的 IRunUtil.IRunnableResult

logErrors boolean:在例外狀況上記錄錯誤。

傳回
CommandStatus CommandStatus 作業的結果。

setEnvVariable

public void setEnvVariable (String name, 
                String value)

設定執行系統指令時要使用的環境變數。

參數
name String:變數名稱

value String:變數值

setEnvVariablePriority

public void setEnvVariablePriority (IRunUtil.EnvPriority priority)

決定是否建立程序時,取消設定環境變數的優先順序是否高於設定值。 取消設定的優先順序較高,亦即在嘗試設定名稱相同的變數時,不會發生此情況,因為系統會不設定該變數。 無法用於預設 IRunUtil 執行個體,

參數
priority IRunUtil.EnvPriority

setInterruptibleInFuture

public void setInterruptibleInFuture (Thread thread, 
                long timeMs)

設為等待一段時間後可中斷。ERROR(/CommandScheduler#shutdownHard())

參數
thread Thread:要中斷的執行緒。

timeMs long:設定中斷前的等待時間。

setLinuxInterruptProcess

public void setLinuxInterruptProcess (boolean interrupt)

允許在達到逾時時,在透過 #runTimed 方法執行的程序中使用 Linux「kill」中斷。 無法用於預設 IRunUtil 執行個體,

參數
interrupt boolean

setRedirectStderrToStdout

public void setRedirectStderrToStdout (boolean redirect)

設定標準錯誤串流,在執行系統指令時重新導向至標準輸出串流。初始值為 false。

參數
redirect boolean:是否要重新導向的新值

setWorkingDir

public void setWorkingDir (File dir)

設定系統指令的工作目錄。

參數
dir File:工作目錄

舒眠

public void sleep (long time)

輔助方法:在指定時間休眠,忽略任何例外狀況。

參數
time long:休眠毫秒。系統會忽略小於或等於 0 的值

未設定這項政策

public void unsetEnvVariable (String key)

取消設定環境變數,如此一來,系統指令就會在沒有這個環境變數的情況下執行。 環境變數可能會繼承父項程序,因此我們需要從 ProcessBuilder.environment() 中刪除環境變數

參數
key String:變數名稱