@@ -0,0 +1,2973 @@
+/**%0A * %0A */%0Apackage com.ethan.testing.examples;%0A%0Aimport java.sql.Connection;%0Aimport java.sql.DriverManager;%0Aimport java.sql.PreparedStatement;%0Aimport java.sql.ResultSet;%0Aimport java.sql.SQLException;%0Aimport java.util.Random;%0A%0Aimport javax.naming.NamingException;%0A%0Aimport com.ethan.testing.MultiThreadTestCase;%0Aimport com.ethan.testing.MultiThreadTestHandler;%0A%0A/**%0A * @author Ethan Tsui created date: 2014/6/18%0A */%0Apublic class TestGetTransactionId extends MultiThreadTestCase %7B%0A%0A    /**%0A     * @param args%0A     */%0A    public static void main(String%5B%5D args) %7B%0A        MultiThreadTestHandler handler = new MultiThreadTestHandler();%0A        handler.setExecutionTimes(50);%0A        handler.setNumbersOfThreads(3);%0A        handler.setTestingClass(TestGetTransactionId.class);%0A        handler.setOutputPath(%22/data/temp/transactionid/%22);%0A        // handler.setOutputCollision(true);%0A        handler.start();%0A%0A    %7D%0A%0A    /**%0A     * %0A     */%0A    public TestGetTransactionId() %7B%0A%0A    %7D%0A%0A    /**%0A     * @see com.ethan.testing.MultiThreadTestCase#execute()%0A     */%0A    @Override%0A    public String execute() %7B%0A%0A        return getInvoiceId();%0A    %7D%0A%0A    %0A    Random random = new Random();%0A    %0A    private String getInvoiceId() %7B%0A%0A        String data = null;%0A        try %7B%0A            Connection conn = getConnection();%0A            boolean error = true;%0A%0A            conn.setAutoCommit(false);%0A%0A            conn.setTransactionIsolation(Connection.TRANSACTION_REPEATABLE_READ);%0A%0A            while (error) %7B%0A                try %7B%0A                    PreparedStatement ps1 = conn.prepareStatement(%22select min(invoice_id) from invoicetable where isused=0%22);%0A                    ResultSet rs1 = ps1.executeQuery();%0A                    if(rs1.next()) %7B%0A                        data = rs1.getString(1);%0A                    %7D%0A                    PreparedStatement psUpdate = conn.prepareStatement(%22update invoicetable set isused=1 where invoice_id=?%22);%0A                    psUpdate.setString(1, data);%0A                    psUpdate.executeUpdate();%0A                    %0A                    conn.commit();%0A                    %0A                    rs1.close();%0A                    ps1.close();%0A                    psUpdate.close();%0A                    %0A                    %0A                    error = false;%0A                %7D catch (Exception err) %7B%0A                    conn.rollback();%0A                    Thread.sleep(random.nextInt(50));%0A                %7D%0A            %7D%0A            conn.close();%0A        %7D catch (Exception err) %7B%0A            err.printStackTrace();%0A        %7D%0A        return data;%0A    %7D%0A%0A    public Connection getConnection() throws SQLException, NamingException %7B%0A%0A        Connection c = null;%0A        try %7B%0A            Class.forName(%22org.postgresql.Driver%22);%0A             c = DriverManager.getConnection(%22jdbc:postgresql://127.0.0.1/testinvoicedb%22, %22invoiceuser%22, %22invoice%22);%0A%0A        %7D catch (Exception e) %7B%0A            e.printStackTrace();%0A        %7D%0A        return c;%0A    %7D%0A%7D%0A

add example