2015-01-09 9 views
0

Bitronix와 함께 분산 된 트랜잭션을 두 개의 데이터 소스로 실행하면서 "경고 된 리소스로 트랜잭션 실행 중"이라는 경고 메시지가 나타납니다. 리소스를 글로벌 트랜잭션에 참여시키는 방법을 이해하는 데 도움을 줄 수 있습니까? 내 코드는 다음과 같습니다경고 : 등록 된 리소스가 0 인 트랜잭션 실행 : Bitronix

import java.sql.Connection; 
    import java.sql.PreparedStatement; 
    import java.sql.SQLException; 

    import javax.sql.DataSource; 
    import javax.transaction.HeuristicMixedException; 
    import javax.transaction.HeuristicRollbackException; 
    import javax.transaction.NotSupportedException; 
    import javax.transaction.RollbackException; 
    import javax.transaction.SystemException; 

    import bitronix.tm.BitronixTransactionManager; 
    import bitronix.tm.TransactionManagerServices; 

    public class TestMain { 

    public static void main(String[] args) { 

    new TestMain().TestDT(); 

    } 

    private void TestDT(){ 

    DataSource dataSourceRemote = ConnectionManager.getDatasourceRemote(); 
    DataSource dataSourceLocal = ConnectionManager.getDatasourceLocal(); 
    Connection con, conn = null; 
    try { 


     /*String remoteDS = "remoteDS"; 
     String localDS = "localDS"; 
     InitialContext ctxRemote = new InitialContext(); 
     ctxRemote.bind(remoteDS, dataSourceRemote);*/ 

     String INSERT_QUERY = "insert emp values (?,?,?,?)"; 

     /*InitialContext ctxLocal = new InitialContext(); 
     ctxLocal.bind(localDS, dataSourceLocal);*/ 
     BitronixTransactionManager btx =   TransactionManagerServices.getTransactionManager(); 
     //DataSource dsRemote = null; 
     //btx.ge 
    //UserTransaction us = 


     try { 

      btx.begin(); 


      //DataSource dsRemote = (DataSource) ctxRemote.lookup(remoteDS); 
      con = dataSourceRemote.getConnection(); 
      //con.setAutoCommit(false); 
      PreparedStatement pstmt = con.prepareStatement(INSERT_QUERY); 

      for(int i=1; i<=5; i++){ 
       pstmt.setInt(1, i); 
       pstmt.setString(2, "Sanjay_"+i); 
       pstmt.setString(3, "123"+i); 
       pstmt.setString(4, "1000"+i); 
       pstmt.execute(); 
      } 



      //DataSource dsLocal = (DataSource) ctxLocal.lookup(localDS); 
      conn = dataSourceLocal.getConnection(); 
      //conn.setAutoCommit(false); 
      PreparedStatement ps = conn.prepareStatement(INSERT_QUERY); 
      for(int i=1; i<=5; i++){ 
       ps.setInt(1, i); 
       ps.setString(2, "Nikhil_"+i); 
       ps.setString(3, "123"+i); 
       ps.setString(4, "1000"+i); 
       ps.execute(); 
      } 

      btx.commit(); 
      con.close(); 
      conn.close(); 

     } catch (NotSupportedException e) { 
      e.printStackTrace(); 
     } catch (SystemException e) { 
      e.printStackTrace(); 
     }catch (SQLException e) { 
      try{ 
       btx.rollback(); 
      }catch (Exception ex) { 
       ex.printStackTrace(); 
      } 
      e.printStackTrace(); 
     }catch (HeuristicRollbackException e) { 
      try{ 
       btx.rollback(); 
      }catch (Exception ex) { 
       ex.printStackTrace(); 
      } 
      e.printStackTrace(); 
     }catch (HeuristicMixedException e) { 
      try{ 
       btx.rollback(); 
      }catch (Exception ex) { 
       ex.printStackTrace(); 
      } 
      e.printStackTrace(); 
     }catch (RollbackException e) { 
      try{ 
       btx.rollback(); 
      }catch (Exception ex) { 
       ex.printStackTrace(); 
      } 
      e.printStackTrace(); 
     }finally{ 
      //try{ 
       btx.shutdown(); 
       //con.close(); 
       //conn.close(); 
      /*}catch (Exception e) { 
       e.printStackTrace(); 
      }*/ 
     } 

     //btx.getTransaction() 
    }catch (Exception e) { 

     e.printStackTrace(); 
    } 

} 
     } 

답변

-1

"0 자원 입대로 거래를 실행하는 것은"단순히 데이터 소스 Bitronix 트랜잭션 관리와 매핑되지 않음을 의미합니다.