我創建了以下FutureTask方法以異步方式運行方法。Java 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中拋出這個異常?
這個問題是重複的。 [這裏是原創](http://stackoverflow.com/questions/3555302/how-to-catch-exceptions-in-futuretask)。 –
Java命名約定:方法名應該是'camelCase'。方法名中的第一個字母不能是大寫字母。雖然.NET語言這樣做,但Java對此不以爲然。 – fge