Which two represents possible system output after all processing has completed?

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)

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)

A.
Begin end

B.
Begin

C.
End

D.
1

E.
<no output>

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.



Leave a Reply 8

Your email address will not be published. Required fields are marked *


Tamer Saleh

Tamer Saleh

A,B
The execution either will start then cancled “so it’ll print begin” or it can be executed faster than it can be canceled, so it’ll print begin Eng

Bala

Bala

B, E
Since first print is a println and next is print and so we dont have something like that in option A and hence it should be B.

Figaro

Figaro

client invokes cancel mathod with parameter mayInterruptIfRunning = true, so there are two possible answers:
1) Begin End – if asynchronous method has been ended before cancel invocation
2) Begin – if asynchronous method has been canceled during its execution

So A and B are correct.

Andrei

Andrei

AE

A Async method cannot be interrupted in the middle, or is fully executed or not.

JavaBatman

JavaBatman

DE is correct one !