From 9c44ef80639b92fa677d0bb7c7a534626486c5b3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=9C=B0=E5=B9=B3=E7=BA=BF?= <22250530@qq.com> Date: Wed, 21 Oct 2015 19:44:41 +0800 Subject: [PATCH] --- .../redkale/service/apns/ApnsService.java | 22 ++++--------------- 1 file changed, 4 insertions(+), 18 deletions(-) diff --git a/src-plugin/com/wentch/redkale/service/apns/ApnsService.java b/src-plugin/com/wentch/redkale/service/apns/ApnsService.java index b5634f299..064a30feb 100644 --- a/src-plugin/com/wentch/redkale/service/apns/ApnsService.java +++ b/src-plugin/com/wentch/redkale/service/apns/ApnsService.java @@ -46,16 +46,12 @@ public class ApnsService implements Service { @Resource(name = "property.apns.buffersize") // protected int apnsbuffersize = 4096; - private final Object socketlock = new Object(); - private boolean inited = false; private final CountDownLatch cdl = new CountDownLatch(1); private SSLSocketFactory sslFactory; - private Socket pushSocket; - @Override public void init(AnyValue conf) { new Thread() { @@ -95,10 +91,6 @@ public class ApnsService implements Service { @Override public void destroy(AnyValue conf) { - try { - if (pushSocket != null) pushSocket.close(); - } catch (Exception e) { - } } private Socket getPushSocket() throws IOException { @@ -108,15 +100,8 @@ public class ApnsService implements Service { } catch (InterruptedException e) { } } - if (this.sslFactory == null) return null; - if (pushSocket == null || pushSocket.isClosed()) { - synchronized (socketlock) { - if (pushSocket == null || pushSocket.isClosed()) { - pushSocket = sslFactory.createSocket(apnspushaddr, apnspushport); - pushSocket.setTcpNoDelay(true); - } - } - } + Socket pushSocket = sslFactory.createSocket(apnspushaddr, apnspushport); + pushSocket.setTcpNoDelay(true); return pushSocket; } @@ -156,7 +141,8 @@ public class ApnsService implements Service { buffer.flip(); Socket socket = getPushSocket(); - socket.getOutputStream().write(buffer.array(), 0, buffer.remaining()); + socket.getOutputStream().write(buffer.array(), 0, buffer.remaining()); + socket.close(); } public static void main(String[] args) throws Exception {