Mike Baranczak
Mike Baranczak

Reputation: 8374

@Asynchronous private method in EJB

I have an asynchronous method in my EJB singleton that's called from another method in the same class. I already know that I can't call the asynchronous method directly, I have to obtain an EJB proxy. The problem is, I don't want the asynchronous method to be visible outside the class; but when I make it private, it's not executed asynchronously. (I'm using Glassfish v3.)

The javadocs don't say anything about the required access level. So should this be considered a bug in Glassfish?

Upvotes: 2

Views: 4419

Answers (2)

David Blevins
David Blevins

Reputation: 19368

That's a very interesting bit of feedback. I can see the value in what you are trying to do. Try marking your bean as an @LocalBean and annotating your @Asynchronous method as protected.

As @LocalBean support is basically done via subclassing the bean class (dynamically or statically), it isn't really possible for the container to override the private method. But I can certainly see your use case. If the protected method approach doesn't work, we can probably add this as an enhancement to EJB.next.

Would still give access to other beans in the same package, but it's at least less public. I've often wished Java had an 'only subclasses' scope. I've almost never used protected and thought, "great, now everyone in my package can access this too."

Upvotes: 1

method annotation cannot be used in private methods. When Glassfish is compiling your EJB it will basically convert your annotation into a piece of code that will surround your code in a proxy. If your method is private it will bypass the proxy Glassfish created... So, in your case I suggest to create a new EJB with your asynchronous method in inject it in your current EJB

Upvotes: 8

Related Questions