nerdexam
Oracle

1Z0-895 · Question #43

A bean developer writes a stateless session bean FooEJB with the following asynchronous business method: @Asynchronous public Future<Integer> fooAsync () { System.out.printIn ("begin"); int i = 1…

The correct answer is D. 1 E. <no output>. Either it will run and return 1, or it will be cancelled and produce no output. Note:EJB 3.1 can 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>…

Session Beans

Question

A bean developer writes a stateless session bean FooEJB with the following asynchronous business method: @Asynchronous public Future<Integer> fooAsync () { System.out.printIn ("begin"); int i = 1; System.out.print("end"); Return new AsyncResult<Integer> (i); } Given the following code, where fooRef is an EJB reference to FooEJB: Future<Integer> fooFuture = fooref.fooAsync(); fooFuture.cancel (true); Which two represents possible system output after all processing has completed? (Choose two)

Options

  • ABegin end
  • BBegin
  • CEnd
  • D1
  • E<no output>

How the community answered

(20 responses)
  • A
    5% (1)
  • B
    5% (1)
  • C
    10% (2)
  • D
    80% (16)

Explanation

Either it will run and return 1, or it will be cancelled and produce no output. Note:EJB 3.1 can 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.

Topics

#asynchronous methods#Future#AsyncResult#cancel

Community Discussion

No community discussion yet for this question.

Full 1Z0-895 Practice