制定新的未来任务
public static class SubmitSMTask implements Callable<SubmitSMResp>{
SubmitSM smRequest;
Session sessionSend;
public SubmitSMTask(Session sessionSend, SubmitSM smRequest) {
this.sessionSend = sessionSend;
this.smRequest = smRequest;
}
@Override
public SubmitSMResp call() throws Exception {
SubmitSMResp response = sessionSend.submit(smRequest);
return response;
}
}
然后调用它。我用 100 毫秒作为超时
ExecutorService executor = Executors.newSingleThreadExecutor();
Future<SubmitSMResp> future = executor.submit(new SubmitSMTask(sessionSend, smRequest));
SubmitSMResp response = future.get(100, TimeUnit.MILLISECONDS);
smsId = response.getMessageId();