private static void disable2PC ( String extractDirectory , String serverName ) throws IOException { String fileName = extractDirectory + File . separator + "wlp" + File . separator + "usr" + File . separator + "servers" + File . separator + serverName + File . separator + "jvm.options" ; BufferedReader br = null ; BufferedWriter bw = null ; StringBuffer sb = new StringBuffer ( ) ; try { String sCurrentLine ; File file = new File ( fileName ) ; // if file doesnt exists, then create it if ( ! file . exists ( ) ) { boolean success = file . createNewFile ( ) ; if ( ! success ) { throw new IOException ( "Failed to create file " + fileName ) ; } } else { // read existing file content br = new BufferedReader ( new InputStreamReader ( new FileInputStream ( fileName ) , "UTF-8" ) ) ; while ( ( sCurrentLine = br . readLine ( ) ) != null ) { sb . append ( sCurrentLine + "\n" ) ; } } // write property to disable 2PC commit String content = "-Dcom.ibm.tx.jta.disable2PC=true" ; bw = new BufferedWriter ( new OutputStreamWriter ( new FileOutputStream ( file . getAbsoluteFile ( ) ) , "UTF-8" ) ) ; bw . write ( sb . toString ( ) ) ; bw . write ( content ) ; } finally { if ( br != null ) br . close ( ) ; if ( bw != null ) bw . close ( ) ; } }
Write property into jvm . options to disable 2PC transactions . 2PC transactions are disabled by default because default transaction log is stored in extract directory and therefore foils transaction recovery if the server terminates unexpectedly .