2017-12-19 15 views
0

こんにちは私は、クエリの問題に例外の後にプロシージャを復元しました。 これはexceptonは私が新しい例外をスローunSetEditingFleet中にoccuresときに起こるものをしようとするコード(それの主要部分)ロック待機タイムアウトが例外のキャッチ後に超過トランザクションメソッド

@Override 
@Async 
@Transactional(rollbackFor=Exception.class) 
public void modifyFleet(User currentUser, FleetForm fleetForm) throws Exception { 
    //Keep the progress status on DB 
    fleetServices.setEditingProgress(fleetForm.getIdFleet(), "Start editing fleet"); 
    Fleet oldFleet = fleetServices.findById(fleetForm.getIdFleet()); 
    //some INSTRUCTIONS 
    if (!(backupFolderFile.mkdirs())) 
     throw new FileSystemException("Error making the folder backup"); 
    try{ 
     //Keep the progress status on DB 
     fleetServices.setEditingProgress(fleetForm.getIdFleet(), "Backup..."); 
     FileUtils.copyDirectory(fleetFile, new File(backupFolder)); 

     //Create fleet with new value 
     Fleet newFleet = newFleetConstructor(fleetForm, oldFleet); 
     //Change operation for all cars of the application 
     int i = 0; 
     for (Car car:oldFleet.getCars()){ 
      //some INSTRUCTIONS 

      //Keep the progress status on DB 
      fleetServices.setEditingProgress(fleetForm.getIdFleet(), "Work on car "+ car.getCarType().getIdCarType() + car.getId()+ " (" + i +" of " + oldFleet.getCars().size() +"): Editing acquisitions file" ); 

     } 

     fleetServices.setEditingProgress(oldFleet.getIdFleet(), "Updating file system fleet path"); 
     utils.unSetEditingFleet(oldFleet.getIdFleet()); 
//   throw new Exception("fleet has been restored Exception"); 
    }catch(Exception e){ 
     //Keep the progress status on DB 
     fleetServices.setEditingProgress(oldFleet.getIdFleet(), "Sorry an error occured during the procedure, wait until restore is ended!"); 
     //Restore the file system procedure 
     restoreProcedure(oldFleet.getIdFleet(), fleetFile, backupFolderFile);  
     //Keep the progress status on DB 
     fleetServices.setEditingProgress(oldFleet.getIdFleet(), ""); 
     utils.unSetEditingFleet(oldFleet.getIdFleet()); 
     //Even with this exception set the fleet as not in editing 
     throw new EditingException("fleet has been restored!"); 
    } 
} 

です:

@Transactional 
public void unSetEditingFleet(Integer idFleet) throws QueryException { 
    try { 
     fleetServices.setEditingFleet(idFleet, false); 
     throw new Exception(); 
//   for(Car car : carServices.findByFleetIdFleet(idFleet)){ 
//    carServices.setEditingCar(car.getIdCar(), false); //Unset cars associated with the fleet 
//   }  
    }catch(Exception e){ 
     throw new QueryException(e); 
    } 
} 

命令fleetServices.setEditingProgress例外のキャッチが発生した後、例外:

Caused by: java.sql.SQLException: Lock wait timeout exceeded; try restarting transaction 
    at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:998) 
    at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3847) 
    at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3783) 
    at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2447) 
    at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2594) 
    at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2545) 
    at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:1901) 
    at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2113) 
    at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2049) 
    at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2034) 
    at org.apache.commons.dbcp.DelegatingPreparedStatement.executeUpdate(DelegatingPreparedStatement.java:105) 
    at org.apache.commons.dbcp.DelegatingPreparedStatement.executeUpdate(DelegatingPreparedStatement.java:105) 
    at org.hibernate.engine.jdbc.internal.ResultSetReturnImpl.executeUpdate(ResultSetReturnImpl.java:208) 
    ... 54 more 

setEditinProgressのコードは次のとおりです。

@Override 
@Transactional(propagation = Propagation.REQUIRES_NEW) //necessary to set immediately the text into the database inside a transactional method. This annotation create a new transaction 
public void setEditingProgress(Integer idFleet, String editingProgress) { 
    fleetRepository.setEditingProgress(idFleet, editingProgress); 
} 

これはデータベースに、操作の進捗状況を設定するため、ユーザーは進捗状況を知ることができます。 なぜキャッチ後にこの例外が発生するのですか?どうすれば修正できるのか知っていますか?

答えて

0

私が知ったことから、別のスレッドがレコードのロックを長すぎるためにデータベースのトランザクションがタイムアウトすることがわかります。同時に、そのテーブルで他のスレッドがどの操作を実行しているかを確認します。あなたが忙しいデシベルの使用を実行している場合here

を示すようなものをブロック取引を把握するためにさまざまな方法があります。

SET GLOBAL innodb_lock_wait_timeout = 5000; 

その後:

SET innodb_lock_wait_timeout = 5000; 

は、回避策として動作しますが、あなたのクエリが必要です最適化する。

関連する問題