liubao68 commented on a change in pull request #1825:
URL: 
https://github.com/apache/servicecomb-java-chassis/pull/1825#discussion_r437823717



##########
File path: 
service-registry/registry-zero-config/src/main/java/org/apache/servicecomb/zeroconfig/server/ServerUtil.java
##########
@@ -179,12 +179,12 @@ private static ServerMicroserviceInstance 
buildServerMicroserviceInstanceFromMap
 
   private static void startListenerForRegisterUnregisterEvent() {
     try {
-      byte[] buffer = new byte[DATA_PACKET_BUFFER_SIZE];
       multicastSocket = new MulticastSocket(PORT);
       group = InetAddress.getByName(GROUP);
       multicastSocket.joinGroup(group); // need to join the group to be able 
to receive the data
 
       while (true) {
+        byte[] buffer = new byte[DATA_PACKET_BUFFER_SIZE];
         DatagramPacket receivePacketBuffer = new DatagramPacket(buffer, 
buffer.length);
         multicastSocket.receive(receivePacketBuffer);
         String receivedPacketString = new 
String(receivePacketBuffer.getData(), ENCODE);

Review comment:
       Maybe you misunderstanding my point. You should do this 
   
   ```
    multicastSocket.receive(receivePacketBuffer);
   int len = multicastSocket.getLength() ;
   if(len > 0) {
      String receivedPacketString = new String(receivePacketBuffer.getData(), 
0, len, ENCODE);
   }
   ```
   
   And you can avoid creating new buffers for each receive, though this is not 
very important because the next receive happens in seconds.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


Reply via email to