Simplest as possible working example for this issue:

  | package test;
  | 
  | import javax.naming.InitialContext;
  | import javax.transaction.Synchronization;
  | import javax.transaction.Transaction;
  | import javax.transaction.TransactionManager;
  | 
  | public class RollbackTest {
  |     public static void test(){
  |             try{
  |             InitialContext ic = new InitialContext();
  |             TransactionManager tm = (TransactionManager)ic.lookup( 
"javax.transaction.TransactionManager" );
  |             try {
  |                             tm.setTransactionTimeout(1);//set 1 sec 
transaction timeout
  |                             tm.begin();//start transaction
  |                             Transaction t = tm.getTransaction();
  |                             t.registerSynchronization(new Synchronization() 
{//add new synchronization handler
  | 
  |                                     public void afterCompletion(int arg0) {
  |                                             
System.out.println("After:"+Thread.currentThread().hashCode());
  |                                     }
  | 
  |                                     public void beforeCompletion() {
  |                                             
System.out.println("Before:"+Thread.currentThread().hashCode());
  |                                     }
  |                             });
  |                             Thread.sleep(20000);//wait 20 secs
  |                             System.out.println("Transaction before 
commit:"+Thread.currentThread().hashCode());
  |                             tm.commit();//try commit tranwsaction, 
TransactionTimedOut exception should be throwed
  |                             System.out.println("Transaction after 
commit:"+Thread.currentThread().hashCode());
  |                     } catch (Exception e) {
  |                             System.out.println("Fake method error: " + 
e.getMessage());
  |                     }
  |             }catch(Exception e){
  |                     e.printStackTrace();
  |             }
  |     }
  | }
  | 

Run this code from any non-transactional context, for example from jsp page.

  | <jsp:directive.page import="test.RollbackTest"/>Hello!!
  | <%
  |     RollbackTest.test();
  | %>
  | 

Output is:
After:-1257420086
Transaction before commit:668113225
Fake method error: Transaction timed out after 0 seconds 
BEA1-00058EF7774602E8BAA1

Note:
when you set sleep() value less than 10 secs, weblogic dosen't create separate 
thread for rollback!

View the original post : 
http://www.jboss.com/index.html?module=bb&op=viewtopic&p=3998182#3998182

Reply to the post : 
http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=3998182
_______________________________________________
jboss-user mailing list
[email protected]
https://lists.jboss.org/mailman/listinfo/jboss-user

Reply via email to