From 9ebe11af8b37d3622d04eabbacd9adef4482640c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=9C=B0=E5=B9=B3=E7=BA=BF?= <22250530@qq.com> Date: Thu, 20 Aug 2015 09:40:01 +0800 Subject: [PATCH] --- .../wentch/redkale/service/apns/ApnsService.java | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src-plugin/com/wentch/redkale/service/apns/ApnsService.java b/src-plugin/com/wentch/redkale/service/apns/ApnsService.java index 149790ce5..c02733094 100644 --- a/src-plugin/com/wentch/redkale/service/apns/ApnsService.java +++ b/src-plugin/com/wentch/redkale/service/apns/ApnsService.java @@ -14,6 +14,7 @@ import java.nio.*; import java.nio.channels.*; import java.nio.charset.*; import java.security.*; +import java.util.concurrent.*; import java.util.logging.*; import javax.annotation.*; import javax.net.ssl.*; @@ -48,6 +49,10 @@ public class ApnsService implements Service { private final Object socketlock = new Object(); + private boolean inited = false; + + private final CountDownLatch cdl = new CountDownLatch(1); + private SSLSocketFactory sslFactory; private Socket pushSocket; @@ -78,6 +83,9 @@ public class ApnsService implements Service { ApnsService.this.sslFactory = context.getSocketFactory(); } catch (Exception e) { logger.log(Level.SEVERE, this.getClass().getSimpleName() + " init SSLContext error", e); + } finally { + inited = true; + cdl.countDown(); } } }.start(); @@ -92,6 +100,12 @@ public class ApnsService implements Service { } private Socket getPushSocket() throws IOException { + if (!this.inited) { + try { + cdl.await(); + } catch (InterruptedException e) { + } + } if (this.sslFactory == null) return null; if (pushSocket == null || pushSocket.isClosed()) { synchronized (socketlock) {