diff --git a/examples/src/OpenDis7Examples/AllPduSender.java b/examples/src/OpenDis7Examples/AllPduSender.java index f6e05370fff3e3a5c3d24c5eddbd992060cf7084..575d9cdc23d18c7204356520c9a5c58f22b25f3e 100755 --- a/examples/src/OpenDis7Examples/AllPduSender.java +++ b/examples/src/OpenDis7Examples/AllPduSender.java @@ -424,23 +424,26 @@ public class AllPduSender InetAddress localMulticastAddress = InetAddress.getByName(DEFAULT_MULTICAST_ADDRESS); MulticastSocket multicastSocket = new MulticastSocket(DEFAULT_MULTICAST_PORT); multicastSocket.joinGroup(localMulticastAddress); + + // keep object instantiations outside of loops for best performance + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + DataOutputStream dos = new DataOutputStream(baos); + byte[] buffer; + Pdu aPdu; + DatagramPacket packet; for (int idx = 0; idx < generatedPdusList.size(); idx++) { - ByteArrayOutputStream baos = new ByteArrayOutputStream(); - DataOutputStream dos = new DataOutputStream(baos); - byte[] buffer; - - Pdu aPdu = generatedPdusList.get(idx); + aPdu = generatedPdusList.get(idx); try { aPdu.marshal(dos); buffer = baos.toByteArray(); - DatagramPacket packet = new DatagramPacket(buffer, buffer.length, localMulticastAddress, DEFAULT_MULTICAST_PORT); + packet = new DatagramPacket(buffer, buffer.length, localMulticastAddress, DEFAULT_MULTICAST_PORT); multicastSocket.send(packet); try { - Thread.sleep(100L); // TODO this kind of delay timing should be in a DIS sender class? + Thread.sleep(250L); // TODO shouldn't this kind of delay timing be in a DIS sender class? } catch (InterruptedException ex) { } String currentPduTypeValuePadded = String.format("%2s", aPdu.getPduType().getValue());