// Path: zebra4j/zebra-boot/src/test/java/com58/zhl/util/DatabaseConnection.java
// public class DatabaseConnection {
// 
// 	private static final String DRIVER="oracle.jdbc.driver.OracleDriver";
// 	
// 	private static final String URL="jdbc:oracle:thin:@localhost:1521:orcl";
// 	
// 	private static final String pwd="scott";
// 	
// 	private static final String name="scott";
// 	
// 	public static Connection getConnection(){
// 		try {
// 			Class.forName(DRIVER);
// 			Connection conn=DriverManager.getConnection(URL, name, pwd);
// 			return conn;
// 		} catch (ClassNotFoundException e) {
// 			e.printStackTrace();
// 		} catch (SQLException e) {
// 			e.printStackTrace();
// 		}
// 		return null;
// 	}
// 	
// 	public static void closeConnection(Connection conn){
// 		try {
// 			conn.close();
// 		} catch (SQLException e) {
// 			e.printStackTrace();
// 		}
// 	}
// 	
// }


import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.concurrent.CountDownLatch;
import com58.zhl.util.DatabaseConnection;
package com58.zhl.concurrent;



/**
 * 打造基于数据库操作的非阻塞算法
 * @author 58_zhl
 *
 */
public class Cptt13_DBNonblock {

	/**
	 * 并发数量
	 */
	private static int count=10;
	
	private static CountDownLatch latch=new CountDownLatch(count);
	
	public static void testConcurrent() throws InterruptedException{
		for(int i=0;i<count;i++){
			Thread th=new AccessDB(i+1);
			th.start();
			if(i+1==count){	//最后一个线程启动完毕
				System.out.println("======================");
			}else{
				Thread.sleep(500);
			}
		}
	}
	
	
	private static class AccessDB extends Thread{
		
		private int id;
		
		public AccessDB(int id){
			this.id=id;
		}
		
		public void run(){
// Path: zebra4j/zebra-boot/src/test/java/com58/zhl/util/DatabaseConnection.java
// public class DatabaseConnection {
// 
// 	private static final String DRIVER="oracle.jdbc.driver.OracleDriver";
// 	
// 	private static final String URL="jdbc:oracle:thin:@localhost:1521:orcl";
// 	
// 	private static final String pwd="scott";
// 	
// 	private static final String name="scott";
// 	
// 	public static Connection getConnection(){
// 		try {
// 			Class.forName(DRIVER);
// 			Connection conn=DriverManager.getConnection(URL, name, pwd);
// 			return conn;
// 		} catch (ClassNotFoundException e) {
// 			e.printStackTrace();
// 		} catch (SQLException e) {
// 			e.printStackTrace();
// 		}
// 		return null;
// 	}
// 	
// 	public static void closeConnection(Connection conn){
// 		try {
// 			conn.close();
// 		} catch (SQLException e) {
// 			e.printStackTrace();
// 		}
// 	}
// 	
// }


// Path: zebra4j/zebra-boot/src/test/java/com58/zhl/concurrent/Cptt13_DBNonblock.java
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.concurrent.CountDownLatch;
import com58.zhl.util.DatabaseConnection;

package com58.zhl.concurrent;



/**
 * 打造基于数据库操作的非阻塞算法
 * @author 58_zhl
 *
 */
public class Cptt13_DBNonblock {

	/**
	 * 并发数量
	 */
	private static int count=10;
	
	private static CountDownLatch latch=new CountDownLatch(count);
	
	public static void testConcurrent() throws InterruptedException{
		for(int i=0;i<count;i++){
			Thread th=new AccessDB(i+1);
			th.start();
			if(i+1==count){	//最后一个线程启动完毕
				System.out.println("======================");
			}else{
				Thread.sleep(500);
			}
		}
	}
	
	
	private static class AccessDB extends Thread{
		
		private int id;
		
		public AccessDB(int id){
			this.id=id;
		}
		
		public void run(){
			Connection conn=DatabaseConnection.getConnection();