RunUtil
public
class
RunUtil
extends Object
implements
IRunUtil
| java.lang.Object | |
| ↳ | com.android.tradefed.util.RunUtil |
用於執行作業的輔助方法集合。
摘要
常數 | |
|---|---|
String |
INHERITIO_PREFIX
|
String |
RUNNABLE_NOTIFIER_NAME
|
公用建構函式 | |
|---|---|
RunUtil()
建立新的 |
|
RunUtil(boolean inheritEnvVars)
|
|
公用方法 | |
|---|---|
void
|
allowInterrupt(boolean allow)
允許/不允許目前執行緒中斷執行。 |
ProcessBuilder
|
createProcessBuilder(Redirect redirect,
|
static
IRunUtil
|
getDefault()
取得預設 |
void
|
interrupt(Thread thread, String message, ErrorIdentifier errorId)
中斷指定執行緒上進行中/即將進行的執行作業。 |
void
|
interrupt(Thread thread, String message)
中斷指定執行緒上進行中/即將進行的執行作業。 |
boolean
|
isInterruptAllowed()
提供 RunUtil 的中斷狀態。 |
Process
|
runCmdInBackground(Redirect redirect,
替代的 |
Process
|
runCmdInBackground(
替代的 |
Process
|
runCmdInBackground(
執行指令並使用 |
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)
Helper method to execute a system command, abort if it takes longer than a specified time, and redirect output to files if specified. |
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)
Helper method to execute a system command that requires stdin input, and aborting if it takes longer than a specified time. |
CommandResult
|
runTimedCmdWithInput(long timeout, String input,
Helper method to execute a system command that requires stdin input, and aborting if it takes longer than a specified time. |
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)
執行系統指令的輔助方法,如果超過指定時間,就會中止。 |
boolean
|
runTimedRetry(long opTimeout, long pollInterval, int attempts, IRunUtil.IRunnableResult runnable)
Block and executes an operation multiple times until it is successful. |
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)
Allow to use linux 'kill' interruption on process running through #runTimed methods when it reaches a timeout. |
void
|
setRedirectStderrToStdout(boolean redirect)
執行系統指令時,將標準錯誤串流重新導向至標準輸出串流。 |
void
|
setWorkingDir(File dir)
設定系統指令的工作目錄。 |
void
|
sleep(long time)
Helper method to sleep for given time, ignoring any exceptions. |
void
|
unsetEnvVariable(String key)
取消設定環境變數,因此系統指令會在沒有這個環境變數的情況下執行。
環境變數可能會從父項程序繼承,因此我們需要從 |
常數
INHERITIO_PREFIX
public static final String INHERITIO_PREFIX
常數值: "inheritio-"
RUNNABLE_NOTIFIER_NAME
public static final String RUNNABLE_NOTIFIER_NAME
常數值: "RunnableNotifier"
公用建構函式
RunUtil
public RunUtil (boolean inheritEnvVars)
| 參數 | |
|---|---|
inheritEnvVars |
boolean |
公用方法
allowInterrupt
public void allowInterrupt (boolean allow)
允許/禁止目前執行緒中斷執行。如果允許,目前執行緒的作業可透過 interrupt(Thread, String) 方法從其他執行緒中斷。
| 參數 | |
|---|---|
allow |
boolean:是否允許在目前執行緒上執行中斷。 |
createProcessBuilder
public ProcessBuilder createProcessBuilder (Redirect redirect,
commandList,
boolean enableCache) | 參數 | |
|---|---|
redirect |
Redirect |
commandList |
|
enableCache |
boolean |
| 傳回 | |
|---|---|
ProcessBuilder |
|
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 |
String:RunInterruptedException 的訊息。 |
errorId |
ErrorIdentifier:代表已知的中斷原因。 |
中斷
public void interrupt (Thread thread,
String message)中斷指定執行緒上正在進行/即將進行的執行作業。在指定執行緒上執行的作業會擲回 RunInterruptedException。
| 參數 | |
|---|---|
message |
String:RunInterruptedException 的訊息。 |
isInterruptAllowed
public boolean isInterruptAllowed ()
提供 RunUtil 的中斷狀態。
| 傳回 | |
|---|---|
boolean |
如果可以中斷執行,則為 true,否則為 false。 |
runCmdInBackground
public Process runCmdInBackground (Redirect redirect,
command) 替代的 runCmdInBackground(String) 方法,可接受 ERROR(/List) 形式的指令引數。
| 參數 | |
|---|---|
redirect |
Redirect:要套用至 ProcessBuilder 的 ERROR(/Redirect)。 |
command |
:包含指定系統指令的 ERROR(/List),以及要執行的選用引數 |
| 傳回 | |
|---|---|
Process |
所執行指令的 Process |
runCmdInBackground
public Process runCmdInBackground (command)
替代的 runCmdInBackground(String) 方法,可接受 ERROR(/List) 形式的指令引數。
| 參數 | |
|---|---|
command |
:包含指定系統指令的 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:要執行的指定系統指令,以及選用的引數 |
| 傳回 | |
|---|---|
Process |
所執行指令的 Process |
runCmdInBackground
public Process runCmdInBackground (Redirect redirect,
String... command)非同步執行系統指令的輔助方法。
啟動指令後會立即傳回。
| 參數 | |
|---|---|
redirect |
Redirect:要套用至 ProcessBuilder 的 ERROR(/Redirect)。 |
command |
String:要執行的指定系統指令,以及選用的引數 |
| 傳回 | |
|---|---|
Process |
所執行指令的 Process |
runEscalatingTimedRetry
public boolean runEscalatingTimedRetry (long opTimeout,
long initialPollInterval,
long maxPollInterval,
long maxTime,
IRunUtil.IRunnableResult runnable)封鎖並執行作業多次,直到成功為止。
以指數方式增加作業嘗試之間的等待時間。執行輪詢伺服器等作業時,可使用這項功能,讓伺服器有時間復原 (如果暫時停機)。
| 參數 | |
|---|---|
opTimeout |
long:單一作業嘗試的等待時間上限 (毫秒) |
initialPollInterval |
long:嘗試作業之間的初始等待時間 |
maxPollInterval |
long:嘗試作業之間的最長等待時間 |
maxTime |
long:嘗試作業的總概略最長時間 |
runnable |
IRunUtil.IRunnableResult:執行 IRunUtil.IRunnableResult |
| 傳回 | |
|---|---|
boolean |
true (如果作業在 maxTime 到期前順利完成) |
runFixedTimedRetry
public boolean runFixedTimedRetry (long opTimeout,
long pollInterval,
long maxTime,
IRunUtil.IRunnableResult runnable)封鎖並執行作業多次,直到成功為止。
| 參數 | |
|---|---|
opTimeout |
long:單一作業嘗試的等待時間上限 (毫秒) |
pollInterval |
long:嘗試作業之間的初始等待時間 |
maxTime |
long:嘗試作業的總概略最長時間 |
runnable |
IRunUtil.IRunnableResult:執行 IRunUtil.IRunnableResult |
| 傳回 | |
|---|---|
boolean |
true (如果作業在 maxTime 到期前順利完成) |
runFixedTimedRetryWithOutputMonitor
public boolean runFixedTimedRetryWithOutputMonitor (long opTimeout,
long idleOutputTimeout,
long pollInterval,
long maxTime,
IRunUtil.IRunnableResult runnable)封鎖並執行作業多次,直到成功為止。也會監控輸出串流的活動,如果指定時間內未觀察到任何串流活動,就會中止作業。如果 idleOutputTimeout 設為零,系統就不會監控串流。
| 參數 | |
|---|---|
opTimeout |
long:單一作業嘗試的等待時間上限 (毫秒) |
idleOutputTimeout |
long:輸出串流上等待輸出的時間上限 (以毫秒為單位) |
pollInterval |
long:嘗試作業之間的初始等待時間 |
maxTime |
long:嘗試作業的總概略最長時間 |
runnable |
IRunUtil.IRunnableResult:執行 IRunUtil.IRunnableResult |
| 傳回 | |
|---|---|
boolean |
true (如果作業在 maxTime 到期前順利完成) |
runTimed
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:ERROR(/OutputStream),標準輸出會重新導向至此。可為空值。 |
stderr |
OutputStream:ERROR(/OutputStream),錯誤輸出內容將重新導向至此。可為空值。 |
command |
String:要執行的指定系統指令,以及選用的引數 |
| 傳回 | |
|---|---|
CommandResult |
包含指令執行結果的 CommandResult |
runTimedCmd
public CommandResult runTimedCmd (long timeout, String... command)
執行系統指令的輔助方法,如果超過指定時間,就會中止。
| 參數 | |
|---|---|
timeout |
long:等待時間上限 (以毫秒為單位)。0 表示沒有逾時。 |
command |
String:要執行的指定系統指令,以及選用的引數 |
| 傳回 | |
|---|---|
CommandResult |
包含指令執行結果的 CommandResult |
runTimedCmdRetry
public CommandResult runTimedCmdRetry (long timeout, long retryInterval, int attempts, String... command)
執行系統指令的輔助方法,如果超過指定時間,就會中止。
| 參數 | |
|---|---|
timeout |
long:每次嘗試等待的最長時間 (以毫秒為單位) |
retryInterval |
long:重試指令之間等待的時間 |
attempts |
int:嘗試次數上限 |
command |
String:要執行的指定系統指令,以及選用的引數 |
| 傳回 | |
|---|---|
CommandResult |
包含指令執行結果的 CommandResult |
runTimedCmdRetryWithOutputMonitor
public CommandResult runTimedCmdRetryWithOutputMonitor (long timeout, long idleOutputTimeout, long retryInterval, int attempts, String... command)
執行系統指令的輔助方法,如果超過指定時間,就會中止。也會監控輸出串流的活動,如果指定時間內未觀察到任何串流活動,就會中止。如果 idleOutputTimeout 設為零,系統就不會監控串流。
| 參數 | |
|---|---|
timeout |
long:每次嘗試等待的最長時間 (以毫秒為單位) |
idleOutputTimeout |
long:輸出串流上等待輸出的時間上限 (以毫秒為單位) |
retryInterval |
long:重試指令之間等待的時間 |
attempts |
int:嘗試次數上限 |
command |
String:要執行的指定系統指令,以及選用的引數 |
| 傳回 | |
|---|---|
CommandResult |
包含指令執行結果的 CommandResult |
runTimedCmdSilently
public CommandResult runTimedCmdSilently (long timeout, String... command)
執行系統指令的輔助方法,如果超過指定時間,就會中止。與 runTimedCmd(long, String) 類似,但不會記錄例外狀況的任何錯誤。
| 參數 | |
|---|---|
timeout |
long:等待時間上限 (毫秒) |
command |
String:要執行的指定系統指令,以及選用的引數 |
| 傳回 | |
|---|---|
CommandResult |
包含指令執行結果的 CommandResult |
runTimedCmdSilentlyRetry
public CommandResult runTimedCmdSilentlyRetry (long timeout, long retryInterval, int attempts, String... command)
執行系統指令的輔助方法,如果超過指定時間,就會中止。與 runTimedCmdRetry(long, long, int, String[]) 類似,但不會記錄例外狀況的任何錯誤。
| 參數 | |
|---|---|
timeout |
long:等待時間上限 (毫秒) |
retryInterval |
long:重試指令之間等待的時間 |
attempts |
int:嘗試次數上限 |
command |
String:要執行的指定系統指令,以及選用的引數 |
| 傳回 | |
|---|---|
CommandResult |
包含指令執行結果的 CommandResult |
runTimedCmdWithInput
public CommandResult runTimedCmdWithInput (long timeout, String input, File stdoutFile, File stderrFile, String... command)
執行系統指令的輔助方法,如果超過指定時間則中止,並將輸出重新導向至指定檔案。
| 參數 | |
|---|---|
timeout |
long:等待逾時時間上限 (以毫秒為單位)。0 表示沒有逾時時間。 |
input |
String:要傳遞至程序的 stdin 輸入內容 |
stdoutFile |
File:ERROR(/File),標準輸出會重新導向至此。可為空值。 |
stderrFile |
File:ERROR(/File),錯誤輸出內容將重新導向至此。可為空值。 |
command |
String:要執行的指定系統指令,以及選用的引數 |
| 傳回 | |
|---|---|
CommandResult |
包含指令執行結果的 CommandResult |
runTimedCmdWithInput
public CommandResult runTimedCmdWithInput (long timeout, String input, String... command)
輔助方法,用於執行需要 stdin 輸入的系統指令,如果超過指定時間,則會中止。
| 參數 | |
|---|---|
timeout |
long:等待時間上限 (毫秒) |
input |
String:要傳遞至程序的 stdin 輸入內容 |
command |
String:要執行的指定系統指令,以及選用的引數 |
| 傳回 | |
|---|---|
CommandResult |
包含指令執行結果的 CommandResult |
runTimedCmdWithInput
public CommandResult runTimedCmdWithInput (long timeout, String input,command)
輔助方法,用於執行需要 stdin 輸入的系統指令,如果超過指定時間,則會中止。
| 參數 | |
|---|---|
timeout |
long:等待時間上限 (毫秒) |
input |
String:要傳遞至程序的 stdin 輸入內容 |
command |
:包含系統指令,以及要執行的選用引數的 ERROR(/List) |
| 傳回 | |
|---|---|
CommandResult |
包含指令執行結果的 CommandResult |
runTimedCmdWithInputRedirect
public CommandResult runTimedCmdWithInputRedirect (long timeout, File inputRedirect, String... command)
輔助方法:執行需要從檔案重新導向 Stdin 的系統指令,如果超過指定時間,則會中止。
| 參數 | |
|---|---|
timeout |
long:等待時間上限 (毫秒) |
inputRedirect |
File:要使用 ProcessBuilder.redirectInput() 重新導向為標準輸入的 ERROR(/File)。如果為空值,系統不會重新導向 stdin。 |
command |
String:要執行的指定系統指令,以及選用的引數 |
| 傳回 | |
|---|---|
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:ERROR(/OutputStream),標準輸出會重新導向至此。可為空值。 |
stderr |
OutputStream:ERROR(/OutputStream),錯誤輸出內容將重新導向至此。可為空值。 |
command |
String:要執行的指定系統指令,以及選用的引數 |
| 傳回 | |
|---|---|
CommandResult |
包含指令執行結果的 CommandResult |
runTimedCmdWithOutputMonitor
public CommandResult runTimedCmdWithOutputMonitor (long timeout, long idleOutputTimeout, String... command)
執行系統指令的輔助方法,如果超過指定時間,就會中止。也會監控輸出串流的活動,如果指定時間內未觀察到任何串流活動,就會中止。如果 idleOutputTimeout 設為零,系統就不會監控串流。
| 參數 | |
|---|---|
timeout |
long:等待時間上限 (以毫秒為單位)。0 表示沒有逾時。 |
idleOutputTimeout |
long:輸出串流上等待輸出的時間上限 (以毫秒為單位) |
command |
String:要執行的指定系統指令,以及選用的引數 |
| 傳回 | |
|---|---|
CommandResult |
包含指令執行結果的 CommandResult |
runTimedRetry
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:如果作業在達到嘗試次數上限前順利完成。 |
runTimedRetryWithOutputMonitor
public boolean runTimedRetryWithOutputMonitor (long opTimeout,
long idleOutputTimeout,
long pollInterval,
int attempts,
IRunUtil.IRunnableResult runnable)封鎖並執行作業多次,直到成功為止。也會監控輸出串流的活動,如果指定時間內未觀察到任何串流活動,就會中止作業。如果 idleOutputTimeout 設為零,系統就不會監控串流。
| 參數 | |
|---|---|
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)
封鎖並執行作業,如果超過指定時間,則會中止作業。此外,也會監控輸出串流的活動,如果指定時間內未觀察到任何串流活動,就會中止。如果 idleOutputTimeout 設為零,系統就不會監控串流。
| 參數 | |
|---|---|
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 的值 |
unsetEnvVariable
public void unsetEnvVariable (String key)
取消設定環境變數,因此系統指令會在沒有這個環境變數的情況下執行。
環境變數可能會從父項程序繼承,因此我們需要從 ProcessBuilder.environment() 中刪除環境變數
| 參數 | |
|---|---|
key |
String:變數名稱 |