다음은 내가하는 일입니다. 나는 2 HashMap<FingerprintData, Long>
을 만들 것입니다. 기본적으로 스트림의 지문 데이터를 System.nanoTime()
의 답장에 매핑하고 있습니다.
그러면 "영원히"실행되는 게임 루프를 만들거나 더 이상 필요하지 않을 때까지 각 반복마다 지문 데이터를 가져 와서 각각 HashMap.keySet().contains(theFingerPrintData)
에서 확인하십시오. 반대의 흐름. 그렇다면 HashMap
에서 해방하고 다음과 같이 지연을 찾으려면 수학을 수행하십시오.
또한 클래스가 지문 데이터로 사용되는지 잘 모르겠습니다. 예를 들어 그냥 FingerprintData
Map<FingerprintData, Long> stream1Timestamps = new HashMap<>();
Map<FingerprintData, Long> stream2Timestamps = new HashMap<>();
StreamClass stream1 = howEverYouFetchStream(1);
StreamClass stream2 = howEverYouFetchStream(2);
while(true /*or if you have conditional to terminate place it here*/){
FingerprintData stream1fpd = stream1.getFingerprintData();
FingerprintData stream2fpd = stream2.getFingerprintData();
if(stream1Timestamps.keySet().contains(stream2fpd)){
Long firstHeard = stream1Timestamps.get(stream2fpd);
System.out.println("stream 2 is delayed:" +System.nanoTime()-firstHeard + " nanoseconds");
stream1Timestamps.remove(stream2fpd);
}else{
stream2Timestamps.put(stream2fpd, System.nanoTime();
}
if(stream2Timestamps.keySet().contains(stream1fpd)){
Long firstHeard = stream2Timestamps.get(stream1fpd);
System.out.println("stream 1 is delayed:" +System.nanoTime()-firstHeard + " nanoseconds");
stream2Timestamps.remove(stream1fpd);
}else{
stream1Timestamps.put(stream1fpd, System.nanoTime();
}
}
이 조금 불통 될 필요가있다 부르지 만, 기본적으로 나는 이것이 당신이 찾고있는 것을 믿습니다.