我创建了以下 FutureTask 方法来异步运行方法。
public FutureTask<Object> SendAggregateEventAsync(final
com.Company.Product.SDK.Device.AggregateEvent.ClassObject
request)
{
FutureTask<Object> futureTask;
futureTask = new FutureTask<Object>(new Runnable() {
public void run()
{
try {
SendAggregateEvent(request);
} catch (ResponseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}, null);
return futureTask;
}
public void SendAggregateEvent(
com.Company.Product.SDK.Device.AggregateEvent.ClassObject
request) throws ResponseException
{
try
{
if(request == null) throw new IllegalArgumentException("request");
String[] s_array = new String[0];
s_array[0] = "EventTime";
String namespace = "http://Product.Company.com/" +
"v1.0/Device/AggregateEvent";
IBindingFactory factory;
factory = BindingDirectory.getFactory(
com.Compant.Product.SDK.Device.AggregateEvent.
ClassObject.class);
String message = ChangeDatesToUTC(MessageHelper.
SerializeObject(factory, request), s_array, namespace);
SendMessage(message);
} catch (JiBXException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
为了编译,我必须在 FutureTask 中捕获 ResponseException,但至关重要的是这个 ResponseException 被抛出到实现应用程序而不被 FutureTask 捕获。有没有办法解决这个问题,我可以从 FutureTask 中抛出这个异常?