Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 953837
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T00:06:53+00:00 2026-05-16T00:06:53+00:00

I have several asynchronous jobs that I would like to transparently handle the exception

  • 0

I have several asynchronous jobs that I would like to transparently handle the exception for. I’d like to put the exception handling logic in another component / class. With Seam 2, I extended an exception handler class.

For instance, I’d like to raise an event with the exception in it so that I can have several components act on it as they see fit. The most common one is one that notifies administrators.

Thanks,

Walter

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T00:06:54+00:00Added an answer on May 16, 2026 at 12:06 am

    Here is an example from Part Three: New Features in EJB 3.1 that you can probably adapt:

    Asynchronous Invocation of Session Beans

    Asynchronous processing is a
    surprisingly common requirement for
    many enterprise applications. Some of
    the most obvious use cases are
    triggering fire-and-forget background
    processes, handling long-running tasks
    while keeping the user interface
    receptive or simply increasing
    application throughput by utilizing
    the benefits of parallel processing.
    The easiest way of implementing
    asynchronous processing in Java EE
    applications today is using Message
    Driven Beans. In fact, the first
    Message Driven Bean example in EJB 3
    in Action is used to implement
    asynchronous order billing. More
    precisely, a Message Driven Bean
    (OrderBillingMDB) asynchronously
    bills the customer after the order is
    confirmed and updates the order
    information with the results of the
    billing attempt once it is completed.
    Figure 1 shows this scenario:

    alt text

    Figure 1: Asynchronous order billing

    While using Message Driven Beans for
    asynchronous processing certainly
    works, it also forces you to deal with
    messaging and JMS, even for relatively
    lightweight functionality. This is
    precisely the problem asynchronous
    session bean invocation is designed to
    solve. With this enhancement, you can
    do asynchronous processing simply by
    annotating a session bean method with
    the @Asynchronous annotation. Let’s
    take a look at the re-factored EJB 3
    in Action example for asynchronous
    billing using the feature:

    @Stateless
    public class OrderBillingServiceBean implements OrderBillingService {
        ...
    
        @Asynchronous
        public void billOrder(Order order) {
            try {
                // Attempt to charge the order.
                bill(order);
                // Send email notification of billing success.
                notifyBillingSuccess(order);
                order.setStatus(OrderStatus.COMPLETE);
            } catch (BillingException be) {
                // Send email notification of billing failure.
                notifyBillingFailure(be, order);
                order.setStatus(OrderStatus.BILLING_FAILED);
            } finally {
                update(order);
            }
        }
    
        ...
    }
    

    Because of the @Asynchronous
    annotation, when the client invokes
    the OrderBillingService.billOrder
    method, the call will return
    immediately instead of blocking until
    the billOrder method finishes
    executing. The EJB container will make
    sure the method gets executed
    asynchronously (probably using
    messaging under the hood). As you can
    see, the return type of the
    asynchronous method is void. This will
    probably be the case for a vast
    majority of asynchronous Session bean
    methods. However, EJB 3.1 can also
    support a return type of
    java.util.concurrent.Future<V>,
    where V represents the resultant
    value of an asynchronous invocation.
    In case you are unfamiliar with it,
    the Future<V> interface allows you
    to do things like cancelling an
    asynchronous invocation, checking if
    an invocation is complete, check for
    exceptions and getting the results of
    an asynchronous invocation. Check out
    the documentation for the Future<V>
    interface here:
    http://java.sun.com/javase/6/docs/api/java/util/concurrent/Future.html.
    Let’s take a quick look at an example
    using the Future return type. In
    the billOrder method in the previous
    example, we set the status of the
    order according to the outcome of the
    billing attempt and updated the order.
    Let’s assume that the invoker updates
    the order themselves and wants to know
    what the status of the billing attempt
    was. We could do this by refactoring
    the billOrder method as follows:

    @Stateless
    public class OrderBillingServiceBean implements OrderBillingService {
        ...
    
        @Asynchronous
        public Future<OrderStatus> billOrder(Order order) {
            try {
                // Attempt to charge the order.
                bill(order);
                // Send email notification of billing success.
                notifyBillingSuccess(order);
                return new AsyncResult<OrderStatus>(OrderStatus.COMPLETE);
            } catch (BillingException be) {
                // Send email notification of billing failure.
                notifyBillingFailure(be, order);
                return new AsyncResult<OrderStatus>
                    (OrderStatus.BILLING_FAILED);
            }
        }
    
        ...
    }
    

    The javax.ejb.AsyncResult<V> object
    is a convenience implementation of the
    Future<V> interface. It takes the
    result of the asynchronous invocation
    as a constructor argument. There’s
    nothing stopping you from using your
    own implementation of Future<V>
    however. Asynchronous invocation
    supports a few other neat features
    like delivery guarantees and
    transacted send semantics. For
    details, check out the spec draft.

    If you have a specific problem, please ask a more specific question 🙂

    See also

    • EJB 3.1 – A Significant Step Towards Maturity
    • The Future<V> Interface
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have several cron jobs and I'd like to perform some calculations on them,
I have several Jenkins parameterized jobs that uses the same parameters and parameters values.
I have several doctrine models that have relationships to other models. Let's call those
I have several php scripts that have the following structures: $count = $_GET['count']; $sort
I have several models grouped in a module like this: #/app/models/blobs/small_text.rb class Blobs::SmallText <
I have several RequiredFieldValidators in an ASP.NET 1.1 web application that are firing on
I have a class WebServiceCaller that uses NSURLConnection to make asynchronous calls to a
I have several ajax requests that return different values (pseudocode ahead) var foo =
Several times I've seen mention that for asynchronous ping is good to use twisted.
I have a blocking function that executes an asynchronous MySQL query and returns the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.