To keep one ApnsService alive, i created a ThreadPoolExecutor to hold threads to send push. here is the code of worker:
public static class PushWorker implements Runnable{
private static final Logger log = Logger.getLogger(PushWorker.class);
private String token;
private String alert;
private int badge;
private String sound;
private ApnsService service;
public PushWorker(ApnsService srv, String t, String a, int b, String s){
token = t;
alert = a;
badge = b;
sound = s;
service = srv;
}
@Override
public void run() {
PayloadBuilder payloadBuilder = APNS.newPayload();
payloadBuilder.sound(sound);
payloadBuilder.badge(badge);
payloadBuilder.alertBody(alert);
String payload = payloadBuilder.build();
service.push(token, payload);
}
}
When i created a worker and executed it in a Threadpool:
ThreadPoolExecutor pool = new ThreadPoolExecutor(corePoolSize, maximumPoolSize, keepAliveTime, TimeUnit.SECONDS,queue);
pool.execute(worker);
the program was terminated at :PayloadBuilder payloadBuilder = APNS.newPayload(); and without any error or exception. But, it can work if in the way below:
PushWorker worker = new PushWorker(service, token, alert, badge, null);
worker.run();
I dont know why the thread was terminated in the Threadpool... Did anyone has the same question?