File tree Expand file tree Collapse file tree 4 files changed +20
-8
lines changed
AndroidExecLibrary/src/main/java/com/excellence/exec
sample/src/main/java/com/excellence/exec/sample Expand file tree Collapse file tree 4 files changed +20
-8
lines changed Original file line number Diff line number Diff line change @@ -28,7 +28,7 @@ public class Commander {
2828 * 默认:不限制并发线程数;指令超时10s终止
2929 */
3030 public static void init () {
31- init (new CommanderOptions .Builder ().setParallelTaskCount (Integer .MAX_VALUE ).setTimeOut (DEFAULT_TIME_OUT ).build ());
31+ init (new CommanderOptions .Builder ().parallelTaskCount (Integer .MAX_VALUE ).timeOut (DEFAULT_TIME_OUT ).build ());
3232 }
3333
3434 /**
Original file line number Diff line number Diff line change @@ -27,7 +27,7 @@ public static class Builder {
2727 *
2828 * @param parallelTaskCount 并发线程数
2929 */
30- public Builder setParallelTaskCount (int parallelTaskCount ) {
30+ public Builder parallelTaskCount (int parallelTaskCount ) {
3131 mParallelTaskCount = parallelTaskCount ;
3232 return this ;
3333 }
@@ -36,7 +36,7 @@ public Builder setParallelTaskCount(int parallelTaskCount) {
3636 *
3737 * @param timeOut ms:执行命令超时时间(存在某些命令会需要人为输入确认,此时命令会一直卡住等待),默认10s超时,终止指令
3838 */
39- public Builder setTimeOut (long timeOut ) {
39+ public Builder timeOut (long timeOut ) {
4040 mTimeOut = timeOut ;
4141 return this ;
4242 }
Original file line number Diff line number Diff line change @@ -14,8 +14,8 @@ implementation 'com.excellence:exec:_latestVersion'
1414// 初始化,默认:不限制并发线程数;指令超时10s终止
1515Commander.init();
1616
17- // 自定义初始化参数:超时1s终止
18- Commander.init(new CommanderOptions.Builder().setTimeOut (1000).build())
17+ // 自定义初始化参数:限制同时进行10个任务, 超时1s终止
18+ Commander.init(new CommanderOptions.Builder().parallelTaskCount(10).timeOut (1000).build())
1919
2020// 创建执行命令
2121推荐方式:
Original file line number Diff line number Diff line change @@ -30,11 +30,23 @@ protected void onCreate(Bundle savedInstanceState) {
3030 mButton .setOnClickListener (new View .OnClickListener () {
3131 @ Override
3232 public void onClick (View v ) {
33- Commander .init (new CommanderOptions .Builder ().setTimeOut ( 1000 ).build ());
33+ Commander .init (new CommanderOptions .Builder ().timeOut ( 10000 ).build ());
3434 mTextView .setText ("" );
35- new CommandTask .Builder ().command ("ls" ).build ().deploy (MainActivity .this );
35+ /**
36+ * 5s超时
37+ */
38+ final CommandTask task = new CommandTask .Builder ().command ("ls" ).timeDelay (5000 ).build ();
39+ task .deploy (MainActivity .this );
3640 // final CommandTask task = Commander.addTask("ls", MainActivity.this);
37- // task.discard();
41+ mButton .postDelayed (new Runnable () {
42+ @ Override
43+ public void run () {
44+ /**
45+ * 延时8s取消任务
46+ */
47+ task .discard ();
48+ }
49+ }, 8000 );
3850 }
3951 });
4052
You can’t perform that action at this time.
0 commit comments