当线程中发生异常时,我想在浏览器中显示友好的错误消息。我在 xhtml 页面中有(类似于 h:message)。只要消息来自同一个线程,它就会显示消息,但在这种情况下不起作用。如何在不持有线程的情况下使其工作,因为该方法应该异步执行?
public void start(final Land lan)
{
try {
Future future = executor.submit(new Callable(){
@Override
public Object call() {
try {
conversion.processLand(lan);
LOG.debug("Finished the execution serverion");
uploadLandPages(lan.getPages(),
lan.getLandOID());
}catch(LanException doc){
LOG.error("LanException is caused due to "+doc.getMessage());
FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_ERROR,"File Conversion Issue","Unfortunately we cannot convert this file, please try again later"));
} catch (ApplicationException apx) {
LOG.error("ApplicationException is caused due to "+apx.getMessage());
FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_ERROR,"File Conversion Issue", "We have successfully converted the file but couldn't save in our server"));
}
return null;
}
});
} catch(Exception e){
LOG.error("Exception caused in the thread which converts the doc due to {}",e.getMessage());
throw new RuntimeException("Couldn't create the Conversion thread");
}
finally {
executor.shutdown();
}
}