Skip to content

Commit

Permalink
Merge pull request #111 from JayWenStar/fix_cpu_bug
Browse files Browse the repository at this point in the history
🍺: 优化远控时CPU占用
  • Loading branch information
ZhouYixun authored Jan 17, 2022
2 parents 58d41ee + 0956178 commit b569073
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import java.io.InputStream;
import java.net.Socket;
import java.util.Queue;
import java.util.concurrent.BlockingQueue;

import static com.sonic.agent.tools.AgentTool.subByteArray;

Expand All @@ -33,15 +34,15 @@ public class InputSocketThread extends Thread {

private IDevice iDevice;

private Queue<byte[]> dataQueue;
private BlockingQueue<byte[]> dataQueue;

private SonicLocalThread miniCapPro;

private AndroidTestTaskBootThread androidTestTaskBootThread;

private Session session;

public InputSocketThread(IDevice iDevice, Queue<byte[]> dataQueue, SonicLocalThread miniCapPro, Session session) {
public InputSocketThread(IDevice iDevice, BlockingQueue<byte[]> dataQueue, SonicLocalThread miniCapPro, Session session) {
this.iDevice = iDevice;
this.dataQueue = dataQueue;
this.miniCapPro = miniCapPro;
Expand All @@ -57,7 +58,7 @@ public IDevice getiDevice() {
return iDevice;
}

public Queue<byte[]> getDataQueue() {
public BlockingQueue<byte[]> getDataQueue() {
return dataQueue;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import java.util.Arrays;
import java.util.List;
import java.util.Queue;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.atomic.AtomicReference;

import static com.sonic.agent.tools.AgentTool.*;
Expand Down Expand Up @@ -73,12 +74,15 @@ public void run() {
byte[] frameBody = new byte[0];
byte[] oldBytes = new byte[0];
int count = 0;
BlockingQueue<byte[]> dataQueue = sendImg.getDataQueue();
while (sendImg.isAlive()) {
Queue<byte[]> dataQueue = sendImg.getDataQueue();
if (dataQueue.isEmpty()) {
continue;
byte[] buffer = new byte[0];
try {
buffer = dataQueue.take();
} catch (InterruptedException e) {
log.error("获取数据流失败:{}", e.getMessage());
e.printStackTrace();
}
byte[] buffer = dataQueue.poll();
int len = buffer.length;
for (int cursor = 0; cursor < len; ) {
int byte10 = buffer[cursor] & 0xff;
Expand Down

0 comments on commit b569073

Please sign in to comment.