Skip to content

Commit 2c25d5c

Browse files
committed
update
1 parent c4d97c6 commit 2c25d5c

File tree

3 files changed

+11
-7
lines changed

3 files changed

+11
-7
lines changed

czxing/src/main/java/me/devilsen/czxing/thread/ExecutorUtil.java

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
import java.util.concurrent.ArrayBlockingQueue;
77
import java.util.concurrent.Executor;
8+
import java.util.concurrent.ExecutorService;
89
import java.util.concurrent.Executors;
910
import java.util.concurrent.SynchronousQueue;
1011
import java.util.concurrent.ThreadFactory;
@@ -16,9 +17,9 @@ public class ExecutorUtil {
1617

1718
private static Executor sMainExecutor;
1819
private static Handler sMainHandler;
19-
private static Executor sCalculateExecutor;
20-
private static Executor sSingleThreadExecutor;
21-
private static Executor sIOExecutor;
20+
private static ExecutorService sCalculateExecutor;
21+
private static ExecutorService sSingleThreadExecutor;
22+
private static ExecutorService sIOExecutor;
2223

2324

2425
private synchronized static Executor getMainExecutor() {
@@ -34,7 +35,7 @@ public void execute(Runnable command) {
3435
return sMainExecutor;
3536
}
3637

37-
public synchronized static Executor getIOExecutor() {
38+
public synchronized static ExecutorService getIOExecutor() {
3839
if (sIOExecutor == null) {
3940
sIOExecutor = new ThreadPoolExecutor(0, Integer.MAX_VALUE,
4041
60L, TimeUnit.SECONDS,
@@ -44,7 +45,7 @@ public synchronized static Executor getIOExecutor() {
4445
return sIOExecutor;
4546
}
4647

47-
public synchronized static Executor getCalculateExecutor() {
48+
public synchronized static ExecutorService getCalculateExecutor() {
4849
if (sCalculateExecutor == null) {
4950
int processors = Runtime.getRuntime().availableProcessors();
5051
sCalculateExecutor = new ThreadPoolExecutor(processors, processors,
@@ -56,7 +57,7 @@ public synchronized static Executor getCalculateExecutor() {
5657
return sCalculateExecutor;
5758
}
5859

59-
public synchronized static Executor getSingleThreadExecutor() {
60+
public synchronized static ExecutorService getSingleThreadExecutor() {
6061
if (sSingleThreadExecutor == null) {
6162
sSingleThreadExecutor = Executors.newSingleThreadExecutor();
6263
}

czxing/src/main/java/me/devilsen/czxing/view/scanview/DetectView.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import me.devilsen.czxing.code.BarcodeDecoder;
99
import me.devilsen.czxing.code.BarcodeFormat;
1010
import me.devilsen.czxing.code.CodeResult;
11+
import me.devilsen.czxing.thread.ExecutorUtil;
1112

1213
/**
1314
* @author : dongSen
@@ -90,6 +91,8 @@ public void stopDetect() {
9091
public void onDestroy() {
9192
super.onDestroy();
9293
isStop = true;
94+
ExecutorUtil.getCalculateExecutor().shutdownNow();
95+
ExecutorUtil.getSingleThreadExecutor().shutdownNow();
9396
if (mDecoder != null) {
9497
mDecoder.destroy();
9598
mDecoder = null;

sample/src/main/java/me/sam/czxing/MainActivity.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ public void openScan(View view) {
8787
.setCornerColor(resources.getColor(R.color.corner))
8888
.setScanLineColors(scanColors)
8989
// .setHorizontalScanLine()
90-
.setBarcodeFormat(BarcodeFormat.EAN_13)
90+
// .setBarcodeFormat(BarcodeFormat.EAN_13)
9191
.setTitle("")
9292
.showAlbum(true)
9393
.setScanNoticeText("扫描二维码")

0 commit comments

Comments
 (0)