Skip to content

Commit 8e05a0a

Browse files
committed
处理阻塞,优化任务销毁
1 parent 905f3be commit 8e05a0a

File tree

3 files changed

+16
-9
lines changed

3 files changed

+16
-9
lines changed

AndroidExecLibrary/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ dependencies {
2929
testImplementation 'junit:junit:4.12'
3030
androidTestImplementation 'com.android.support.test:runner:1.0.2'
3131
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
32-
implementation 'io.reactivex.rxjava2:rxjava:2.2.0'
33-
implementation 'io.reactivex.rxjava2:rxandroid:2.0.2'
32+
implementation 'io.reactivex.rxjava2:rxjava:2.2.3'
33+
implementation 'io.reactivex.rxjava2:rxandroid:2.1.0'
3434
}
3535

3636
/*********************上传jCenter依赖*********************/

AndroidExecLibrary/src/main/java/com/excellence/exec/CommandTask.java

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
import io.reactivex.functions.Consumer;
1414
import io.reactivex.schedulers.Schedulers;
1515

16+
import static com.excellence.exec.ProcessUtils.closeStream;
17+
1618
/**
1719
* <pre>
1820
* author : VeiZhang
@@ -235,14 +237,20 @@ public void accept(Long aLong) throws Exception {
235237
BufferedReader stdin = new BufferedReader(new InputStreamReader(mProcess.getInputStream()));
236238
StringBuilder result = new StringBuilder();
237239
String line = null;
238-
while (mStatus == STATUS_RUNNING && (line = stdin.readLine()) != null) {
239-
if (mStatus == STATUS_RUNNING) {
240-
restartTimer();
241-
mIListener.onProgress(line);
242-
result.append(line);
240+
try {
241+
while (mStatus == STATUS_RUNNING && (line = stdin.readLine()) != null) {
242+
if (mStatus == STATUS_RUNNING) {
243+
restartTimer();
244+
mIListener.onProgress(line);
245+
result.append(line);
246+
}
243247
}
248+
} catch (Exception e) {
249+
e.printStackTrace();
250+
} finally {
251+
closeStream(mProcess);
252+
stdin.close();
244253
}
245-
stdin.close();
246254
resetTimer();
247255
if (mStatus == STATUS_RUNNING) {
248256
mIListener.onSuccess(result.toString());

AndroidExecLibrary/src/main/java/com/excellence/exec/ProcessUtils.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,6 @@ public static void closeStream(@NonNull Process process) {
6969
}
7070

7171
public static void destroyProcess(@NonNull Process process) {
72-
closeStream(process);
7372
killProcess(process);
7473
}
7574
}

0 commit comments

Comments
 (0)