Aborting a client-started operation on a session bean

Discussions

EJB design: Aborting a client-started operation on a session bean

  1. I have an interesting problem (at least for me). Say I have a session bean and a client that calls a method on that session bean. The session bean method performs a fairly long operation, say updating hundreds of rows in the database. The client, getting annoyed of waiting, decides to abort. The problem is, how do I implement abort? Since execution is still on the session bean, the call hasn't returned to the client yet. That means the client must make another call to abort to the session bean. But there is no guarantee that the abort call will be served by the same session bean. And you can't do the long operation on a different thread either, since you can't start a thread in a session bean. Anybody has a pattern or idea how to solve this problem?

    thanks

    mgop
  2. I can think of two ideas:
    1.Create checkpoints inside the long run operation,
    set your continue flag somewhere and let those checkpoints verify it.
    2.Create a conversation between client and server, so that
    client has direct control, the drawback is the network roundtrips..

  3. hi mahesh,
    same problem i am also facing.please let me know at rajireddy at hexaware dot co dot in if you get the solution for your problem.i am having one idea.put one public volatile flag in your session bean which is doing long processing.if you want to abort that process,let other bean change that flag.during the processing allways check this flag.if flag is changed then abort your process.if get better idea or solution please let me know.

    regards
    raju
  4. <q>put one public volatile flag in your session bean which is doing long processing.if you want to abort that process,let other bean change that flag</q>
    This is wrong,it won't work under EJB's single threaded
    model,the wrong way is create a flag externally and poll it.
  5. Oops..the second "wrong" should be "right".
  6. System.out.println("Create Transaction");
    UserTx = (UserTransaction) context.lookup("javax.transaction.UserTransaction");
                
    System.out.println("TimeOut set to 15 sec");
    UserTx.setTransactionTimeout(15);



  7. creating flag externally means where i have to put my flag.
    with user transaction i cant time out my process.i don't want to roll back my transaction.i need up to what stage is my procssing is over i have to save this to my temporary table.in future i may continue the process where i left.
  8. database,JNDI,CORBA/RMI object...
  9. Hi,
    Why not using JMS? It will be easier for you to use ansynchronous communication.

    Lofi.