package backend.utils;

import java.sql.Connection;
import java.util.*;

public class DBConnectionPool {
    private static final int MAX_CONNECTION = 10;
    private static Queue<Connection> connectionQueue;
    static{
        connectionQueue = new LinkedList<>();
        for(int i=0;i<MAX_CONNECTION;++i)
            connectionQueue.add(backend.utils.DBHelper.getInstance().getConnection());
    }
    public static Connection getConnection(){
        if(connectionQueue.isEmpty())
            return null;
        return connectionQueue.poll();
    }

    public static void releaseConnection(Connection conn){
        if(conn==null)
            return;
        connectionQueue.add(conn);
    }
}
