Discussions

EJB programming & troubleshooting: Is recursive method call allowed in an EJB ?

  1. Is recursive method call allowed in an EJB ? (2 messages)

    Hi all ,

    Is a recursive method call allowed in an EJB (either 1.x or 2.0) given that the method is a remote method ?

    Example :
    EJB has a remote method called doMethod(int i).Does the EJB specs allows for the following ?:

    public void doMethod(int i) {
        if (i < 10) {
          doMethod(i++);
        }
    }

    I know that re-entrant beans are dangerous and not recommended, but would a simple recursive method call like above be categorized as re-entrant ?

    Thanks.
    Kean
  2. It does. But you can't make reentrant calls without making the bean explicitly reentrant in the DD.
  3. This call is not reentrant. This is reentrant:

    public void doMethod(int i) {
       MyInterface remoteThis = (MyInterface)ejbContext.getEJBObject();
       remoteThis.doMethod(i-1);
    }

    Calls that do not go through the remote interface are not mediated by the container, and they are not re-entrancies. The spec is a little vague about this, but there is no way containers will not allow this, because many EJBs assume that's what the spec ment. Anyway, I think they won't :)

    Gal