You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@plc4x.apache.org by cd...@apache.org on 2020/01/30 14:17:53 UTC
[plc4x] 01/03: - Changed the way the nanosecond sleep is done to a
less CPU intense way.
This is an automated email from the ASF dual-hosted git repository.
cdutz pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/plc4x.git
commit 2a8dccc0719924edade1c67824b9e46d3be3070b
Author: Christofer Dutz <ch...@c-ware.de>
AuthorDate: Wed Jan 29 17:08:20 2020 +0100
- Changed the way the nanosecond sleep is done to a less CPU intense way.
---
.../plc4x/java/utils/pcapsockets/netty/PcapSocketChannel.java | 8 +++++---
1 file changed, 5 insertions(+), 3 deletions(-)
diff --git a/plc4j/utils/pcap-sockets/src/main/java/org/apache/plc4x/java/utils/pcapsockets/netty/PcapSocketChannel.java b/plc4j/utils/pcap-sockets/src/main/java/org/apache/plc4x/java/utils/pcapsockets/netty/PcapSocketChannel.java
index 8135310..2391575 100644
--- a/plc4j/utils/pcap-sockets/src/main/java/org/apache/plc4x/java/utils/pcapsockets/netty/PcapSocketChannel.java
+++ b/plc4j/utils/pcap-sockets/src/main/java/org/apache/plc4x/java/utils/pcapsockets/netty/PcapSocketChannel.java
@@ -39,6 +39,7 @@ import java.io.OutputStream;
import java.net.SocketAddress;
import java.net.SocketTimeoutException;
import java.sql.Timestamp;
+import java.util.concurrent.TimeUnit;
/**
* @author julian
@@ -212,9 +213,10 @@ public class PcapSocketChannel extends OioByteStreamChannel {
* @param numNanos number of nano-seconds to wait.
*/
private void nanoSecondSleep(long numNanos) {
- long endTime = System.nanoTime() + numNanos;
- while(endTime > System.nanoTime()) {
- // Do Nothing ...
+ try {
+ TimeUnit.NANOSECONDS.sleep(numNanos);
+ } catch (InterruptedException e) {
+ Thread.currentThread().interrupt();
}
}