为了让一个ApnsService
保持活跃,我创建了一个ThreadPoolExecutor
来保持线程发送推送。下面是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);
}
}
字符串
当我创建一个worker并在Threadpool
中执行它时:
ThreadPoolExecutor pool = new ThreadPoolExecutor(corePoolSize, maximumPoolSize, keepAliveTime, TimeUnit.SECONDS,queue);
pool.execute(worker);
型
程序终止于:PayloadBuilder payloadBuilder = APNS.newPayload();
,没有任何错误或异常。但是,如果按照以下方式,它可以工作:
PushWorker worker = new PushWorker(service, token, alert, badge, null);
worker.run();
型
我不知道为什么线程在Threadpool
中终止.有人有同样的问题吗?
1条答案
按热度按时间krugob8w1#
尝试使用
字符串
相反