david_b [http://community.jboss.org/people/david_b] created the discussion

"Cancelling an @Asynchronous method with Future.cancel"

To view the discussion, visit: http://community.jboss.org/message/583431#583431

--------------------------------------------------------------
I am writing an enterprise Java application that uses aynchronous EJB 3.1 
methods to execute a number of tasks in parallel. The app is currently running 
on JBoss AS 6.0.0 Final.

To support cancelling a long running task I have been attempting to use the 
Future interface. Unfortunately calling future.cancel(true)appears to have no 
effect on the session context of the bean executing the task, despite the fact 
that cancel is returning true.

I have a simple interface:

public interface AsyncInterface
{
    Future run() throws Exception;
} 

With a bean implementation as follows:

@Stateless@Remote(AsyncInterface.class)public class AsyncBean{    @Resource 
SessionContext myContext;    @Asynchronous    public Future(result);     }} 


The asynchronous method is called from another Stateless EJB like so:

InitialContext ctx = new InitialContext();AsyncInterface async = 
(AsyncInterface)ctx.lookup("AsyncBean/remote");Future future = async.run();if( 
future.cancel(true) ){     System.out.println("future.cancel() returned 
true");}else{     System.out.println("future.cancel() returned false");} 


The output from the AsyncBean is an endless stream of "Working"; it never 
detects the cancellation.

I haven't found much sample code using Futures to cancel an @Asynchronous EJB 
call. Is using the session context the correct way of checking for 
cancellation? Is there a better method for cancelling the asynchronous call?
--------------------------------------------------------------

Reply to this message by going to Community
[http://community.jboss.org/message/583431#583431]

Start a new discussion in EJB3 at Community
[http://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2029]

_______________________________________________
jboss-user mailing list
[email protected]
https://lists.jboss.org/mailman/listinfo/jboss-user

Reply via email to