jmeter-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From fschumac...@apache.org
Subject svn commit: r1783514 - /jmeter/trunk/src/core/org/apache/jmeter/util/ShutdownClient.java
Date Sat, 18 Feb 2017 11:11:02 GMT
Author: fschumacher
Date: Sat Feb 18 11:11:02 2017
New Revision: 1783514

URL: http://svn.apache.org/viewvc?rev=1783514&view=rev
Log:
Use try-with statement to close socket.

Modified:
    jmeter/trunk/src/core/org/apache/jmeter/util/ShutdownClient.java

Modified: jmeter/trunk/src/core/org/apache/jmeter/util/ShutdownClient.java
URL: http://svn.apache.org/viewvc/jmeter/trunk/src/core/org/apache/jmeter/util/ShutdownClient.java?rev=1783514&r1=1783513&r2=1783514&view=diff
==============================================================================
--- jmeter/trunk/src/core/org/apache/jmeter/util/ShutdownClient.java (original)
+++ jmeter/trunk/src/core/org/apache/jmeter/util/ShutdownClient.java Sat Feb 18 11:11:02 2017
@@ -39,11 +39,12 @@ public class ShutdownClient {
         }
         String command = args[0];
         System.out.println("Sending "+command+" request to port "+port);
-        DatagramSocket socket = new DatagramSocket();
-        byte[] buf = command.getBytes("ASCII");
-        InetAddress address = InetAddress.getByName("localhost");
-        DatagramPacket packet = new DatagramPacket(buf, buf.length, address, port);
-        socket.send(packet);
-        socket.close();
+        try (DatagramSocket socket = new DatagramSocket()) {
+            byte[] buf = command.getBytes("ASCII");
+            InetAddress address = InetAddress.getByName("localhost");
+            DatagramPacket packet = new DatagramPacket(buf, buf.length, address,
+                    port);
+            socket.send(packet);
+        }
     }
 }



Mime
View raw message