我有两个无状态会话Bean。呼叫层次结构类似于:
MyClass-> UserManagerBean-> BookManagerBean
MyClass通过JNDI查找远程获取UserManagerBean。
反过来,UserManagerBean通过JNDI查找远程获取BookManagerBean。
BookManagerBean引发BookException。
问题:
在从BookManagerBean引发异常之前,我能够看到日志,但是当我在UserManagerBean中捕获此异常时,线程会移到某个地方,并且永远不会出现在UserManagerBean的catch块中。看起来容器吞下了此异常。这导致STUCK线程。
注意:令人惊讶的是,相同的代码可在其他5个WLS实例上工作,但仅在一台服务器上会出现问题。您是否认为有关此问题的任何weblogic配置?
public class MyClass {
public void findBook(Long bookId) throws Exception{
try{
UserManagerBean userManager = (UserManager) JNDIServiceLocator.getInstance().getRemoteObject(jndiName, 'UserManager' );
userManager.find(bookId);
}catch (Exception e){
Log.log("Exception in MyClass.findBook"); // Thread does not come back to this point. This logger is not getting printed
throw e;
}
UserManagerBean如下:
@Stateless(mappedName ="UserManager")
@Remote(UserManager.class)
public class UserManagerBean {
public Book findBook(Long bookId) throws Exception{
try{
BookManagerBean bookManager = (BookManagerBean) JNDIServiceLocator.getInstance().getRemoteObject(jndiName, 'BookManager' );
bookManager.find(bookId);
}catch (Exception e){
Log.log("Exception in UserManagerBean.findBook"); // **** Thread does not come back to this point. This logger is not getting printed
throw e;
}
}
BookManagerBean类如下所示:
@Stateless(mappedName ="BookManager")
@Remote(BookManagerBean .class)
public class BookManagerBean {
public Book findBook(Long bookId) throws Exception{
try{
//Logic to find Book
}catch (Exception e){
Log.log("Exception");
throw e;
}
}
}
这有效:
如果我更改UserManagerBean中的代码以使用new运算符创建Bean,则会从BookManagerBean中引发异常。
BookManagerBean bookManager = new BookManagerBean();
bookManager.find(bookId);
最佳答案
您可能必须创建自己的“自定义异常”并用进行注释
javax.ejb.ApplicationException.
-阿米特