From be420770d73f2394c87b061664d464b12f9e80f6 Mon Sep 17 00:00:00 2001 From: Michael Laccetti Date: Tue, 12 Jul 2016 11:41:32 -0400 Subject: [PATCH] Integrated the fixes from https://github.com/fernandospr/javapns-jdk16/pull/5/files - should clean up a memory leak --- src/main/java/javapns/Push.java | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/main/java/javapns/Push.java b/src/main/java/javapns/Push.java index 1094a2e..cbafd9c 100644 --- a/src/main/java/javapns/Push.java +++ b/src/main/java/javapns/Push.java @@ -211,16 +211,21 @@ public static PushedNotifications payload(final Payload payload, final Object ke if (numberOfThreads <= 0) { return sendPayload(payload, keystore, password, production, devices); } + final AppleNotificationServer server = new AppleNotificationServerBasicImpl(keystore, password, production); final List deviceList = Devices.asDevices(devices); final NotificationThreads threads = new NotificationThreads(server, payload, deviceList, numberOfThreads); threads.start(); + try { threads.waitForAllThreads(true); } catch (final InterruptedException e) { logger.error(e.getMessage(), e); } - return threads.getPushedNotifications(); + + final PushedNotifications notifications = threads.getPushedNotifications(); + threads.destroy(); + return notifications; } /** @@ -271,16 +276,21 @@ public static PushedNotifications payloads(final Object keystore, final String p if (numberOfThreads <= 0) { return sendPayloads(keystore, password, production, payloadDevicePairs); } + final AppleNotificationServer server = new AppleNotificationServerBasicImpl(keystore, password, production); final List payloadPerDevicePairs = Devices.asPayloadsPerDevices(payloadDevicePairs); final NotificationThreads threads = new NotificationThreads(server, payloadPerDevicePairs, numberOfThreads); threads.start(); + try { threads.waitForAllThreads(true); } catch (final InterruptedException e) { logger.error(e.getMessage(), e); } - return threads.getPushedNotifications(); + + final PushedNotifications notifications = threads.getPushedNotifications(); + threads.destroy(); + return notifications; } /**