From 9e2a83e3d1b14a1937e9d9498c538d3abefe63f0 Mon Sep 17 00:00:00 2001 From: PV Date: Thu, 29 Jun 2017 10:30:46 +0530 Subject: [PATCH] correcting the synchronization --- .../java/com/adroitandroid/near/connect/NearConnectImpl.java | 4 ++-- .../com/adroitandroid/near/discovery/UdpServerService.java | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/near/src/main/java/com/adroitandroid/near/connect/NearConnectImpl.java b/near/src/main/java/com/adroitandroid/near/connect/NearConnectImpl.java index dd37184..ad2d167 100644 --- a/near/src/main/java/com/adroitandroid/near/connect/NearConnectImpl.java +++ b/near/src/main/java/com/adroitandroid/near/connect/NearConnectImpl.java @@ -51,7 +51,7 @@ public void onServiceConnected(ComponentName name, IBinder service) { Host candidateHost = null; long jobId = 0; while (sendDataQueue.size() > 0) { - synchronized (this) { + synchronized (NearConnectImpl.this) { if (sendDataQueue.size() > 0) { candidateData = sendDataQueue.remove(0); candidateHost = sendDestQueue.remove(0); @@ -105,7 +105,7 @@ public void run() { @Override public long send(byte[] bytes, Host peer) { long jobId = System.currentTimeMillis(); - synchronized (this) { + synchronized (NearConnectImpl.this) { sendDataQueue.add(bytes); sendDestQueue.add(peer); sendJobQueue.add(jobId); diff --git a/near/src/main/java/com/adroitandroid/near/discovery/UdpServerService.java b/near/src/main/java/com/adroitandroid/near/discovery/UdpServerService.java index 996ef28..7a03479 100644 --- a/near/src/main/java/com/adroitandroid/near/discovery/UdpServerService.java +++ b/near/src/main/java/com/adroitandroid/near/discovery/UdpServerService.java @@ -164,7 +164,7 @@ private static void setListener(UdpBroadcastListener listener) { private void updateListenersTo(UdpBroadcastListener listener) { mListener = listener; - synchronized (this) { + synchronized (UdpBroadcastListeningHandler.this) { for (StaleHostHandler hostHandler : mHostHandlerMap.values()) { hostHandler.setListener(listener); } @@ -199,7 +199,7 @@ public void handleMessage(Message msg) { StaleHostHandler handler = mHostHandlerMap.get(host); if (handler == null) { handler = new StaleHostHandler(host, mHostHandlerMap, mListener); - synchronized (this) { + synchronized (UdpBroadcastListeningHandler.this) { mHostHandlerMap.put(host, handler); } if (mListener != null) {