En: I use surfaceview mapping (ecg) because need different speed of two ecg,so I created two custom extends surfaceview class open thread in the surfaceCreated ,thread to the rest of the mechanism to realize how long time, Question: when there is only one such view my thread execution rate is good, but if the two custom surfaceview is created, two threads are open, the second will appear timeout phenomenon seriously, Analysis: at first, I thought it was the same holder object. I couldn't find the answer and needed help
Code:
Runnable drawRunnable = new Runnable() {
@Override
public void run() {
while (isRunning) {
long startTime = System.currentTimeMillis();
startDrawWave();
long endTime = System.currentTimeMillis();
try {
if (endTime - startTime < sleepTimeRun) {
if (chaoShi > 0) {
if (((sleepTimeRun - (endTime - startTime)) - chaoShi) >= 0) {
Thread.sleep((sleepTimeRun - (endTime - startTime)) - chaoShi);
chaoShi = 0;
} else {
chaoShi -= sleepTimeRun - (endTime - startTime);
}
} else {
Thread.sleep(sleepTimeRun - (endTime - startTime));
}
} else {
chaoShi += (endTime - startTime) - sleepTimeRun;
}
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
}
};
if only one tartDrawWave();normal but create two custom surfceview have two startDrawWave(), can time consuming; A dozen times more than normal