簡體   English   中英

執行XA事務時,DB2死鎖問題SQLCODE = -911,SQLERRMC = 68

[英]DB2 deadlock issue SQLCODE=-911, SQLERRMC=68 while performing XA transaction

我正在研究嘗試實現兩階段提交的示例jdbc代碼。 有2個數據源,都符合DB2和XA。 創建了2個單獨的jdbc連接。 我正在使用Atomikos作為TM。 使用這些連接,可以對數據源進行更新。 但是,更新查詢未執行,並返回-911錯誤。 我無法弄清僵局的原因和發生地點。 而且,兩個連接都是獨立的並且不相關,那么為什么會有任何死鎖/超時?

....   
     try{

        //Get the datasource connection using jndi custom class

        JndiConn jcon1 = new JndiConn("jdbc/myDatasource1");
        JndiConn jcon2 = new JndiConn("jdbc/myDatasource2");
        UserTransactionImpl utx = new UserTransactionImpl();
        try{
            //Begin transaction             
            utx.begin();

            //Get the connection from the DB
            conn1 = jcon1.ds.getConnection();
            conn2 = jcon2.ds.getConnection();

            //Reading the data from the form
            int frmAccntNum = Integer.parseInt(req.getParameter("frmAccnt"));
            int toAccntNum = Integer.parseInt(req.getParameter("toAccnt"));
            int amt = Integer.parseInt(req.getParameter("amt"));

            //Create a statement from the Connection

            try{
                String selectQuery = "select AccountNumber, Balance from Accounts where AccountNumber =? with ur";
                PreparedStatement stmt = conn1.prepareStatement(selectQuery);
                stmt.setInt(1,frmAccntNum);
                ResultSet rs = stmt.executeQuery();
                rs.next();
                Account frmAccnt = new Account(rs.getInt(1),rs.getInt(2));
                int tempBal = frmAccnt.getBalance();

                PreparedStatement stmt2 = conn2.prepareStatement(selectQuery);
                stmt2.setInt(1, toAccntNum);
                ResultSet rs1 = stmt.executeQuery();
                rs1.next();
                Account toAccnt = new Account(rs1.getInt(1),rs1.getInt(2));
                int tempBal2 = toAccnt.getBalance();

                }
                Operations t1 = new Operations();
                if(t1.checkAmt(frmAccnt,amt)){
                    t1.Withdraw(frmAccnt, amt);
                    t1.Deposit(toAccnt, amt);
                }


                String updateQuery = "update Accounts set Balance = ? where AccountNumber= ? with ur";
                stmt = conn1.prepareStatement(updateQuery);
                stmt.setInt(1, frmAccnt.getBalance());
                stmt.setInt(2,frmAccnt.getAccountNumber());
                stmt.executeUpdate();

                stmt2 = conn2.prepareStatement(updateQuery);
                stmt2.setInt(1, toAccnt.getBalance());
                stmt2.setInt(2,toAccnt.getAccountNumber());
                stmt2.executeUpdate();
                //int r1 = stmt.executeUpdate("update Accounts set Balance = "+frmAccnt.getBalance()+"where AccountNumber="+frmAccnt.getAccountNumber());

                stmt.close();
                stmt2.close();

            }catch(SQLException sq){
                System.out.println("Setting Rollback true");
                sq.printStackTrace();
                rollback = true;
            }
        }catch(Exception ex){
            ex.printStackTrace();
        }finally{
            if(!rollback){
                try{
                    utx.commit();
                }catch(Exception e){
                    System.out.println("Commit Exception");
                    e.printStackTrace();
                    rollback = true;
                    try {
                        utx.rollback();
                    } catch (Exception e1) {
                        // TODO Auto-generated catch block
                        e1.printStackTrace();
                    } 
                }
            }
            else{
                try {
                    utx.rollback();
                } catch (Exception e2) {
                    // TODO Auto-generated catch block
                    e2.printStackTrace();
                } 
            }
            try {
                conn1.close();
                conn2.close();
            } catch (SQLException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }

        }   
    }catch(NamingException nme){
        nme.printStackTrace();
    }

因為這個:

ResultSet rs1 = stmt.executeQuery();

你要

ResultSet rs1 = stmt2.executeQuery();

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM