一个连接池的例子(来自JIVE)(5)

//文件:DbConnectionProvider.java

package com.qingtuo.db.pool;

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

public abstract class DbConnectionProvider {

    /** Dummy values. Override in subclasses. **/
    private static final String NAME = "";
    private static final String DESCRIPTION = "";
    private static final String AUTHOR = "";
    private static final int MAJOR_VERSION = 0;
    private static final int MINOR_VERSION = 0;
    private static final boolean POOLED = false;

    /**
     * Returns the name of the connection provider.
     */
    public String getName() {
        return NAME;
    }

    /**
     * Returns a description of the connection provider.
     */
    public String getDescription() {
        return DESCRIPTION;
    }

    /**
     * Returns the author of the connection provider.
     */
    public String getAuthor() {
        return AUTHOR;
    }

    /**
     * Returns the major version of the connection provider, i.e. the 1 in 1.0.
     */
    public int getMajorVersion() {
        return MAJOR_VERSION;
    }

    public int getMinorVersion() {

        return MINOR_VERSION;

    }

    /**
     * Returns true if this connection provider provides connections out
     * of a connection pool.
     */
    public boolean isPooled() {
        return POOLED;
    }

    /**
     * Returns a database connection. When a Jive component is done with a
     * connection, it will call the close method of that connection. Therefore,
     * connection pools with special release methods are not directly
     * supported by the connection provider infrastructure. Instead, connections
     * from those pools should be wrapped such that calling the close method
     * on the wrapper class will release the connection from the pool.
     */
    public abstract Connection getConnection();

    /**
     * Starts the connection provider. For some connection providers, this
     * will be a no-op. However, connection provider users should always call
     * this method to make sure the connection provider is started.
     */
    protected abstract void start();

    /**
     * This method should be called whenever properties have been changed so
     * that the changes will take effect.
     */
    protected abstract void restart();

    /**
     * Tells the connection provider to destroy itself. For many connection
     * providers, this will essentially result in a no-op. However,
     * connection provider users should always call this method when changing
     * from one connection provider to another to ensure that there are no
     * dangling database connections.
     */
    protected abstract void destroy();

    /**
     * Returns the value of a property of the connection provider.
     *
     * @param name the name of the property.
     * @returns the value of the property.
     */
    public abstract String getProperty(String name);

    /**
     * Returns the description of a property of the connection provider.
     *
     * @param name the name of the property.
     * @return the description of the property.
     */
    public abstract String getPropertyDescription(String name);

    /**
     * Returns an enumeration of the property names for the connection provider.
     */
    public abstract Enumeration propertyNames();

    /**
     * Sets a property of the connection provider. Each provider has a set number
     * of properties that are determined by the author. Trying to set a non-
     * existant property will result in an IllegalArgumentException.
     *
     * @param name the name of the property to set.
     * @param value the new value for the property.
     */
    public abstract void setProperty(String name, String value);
   
}

时间: 2024-09-30 22:13:21

一个连接池的例子(来自JIVE)(5)的相关文章

一个连接池的例子(说明)

这个连接池是直接从JIVE中取出来的,进行了一下修改,使得连接参数直接在程序中设定而不是从属性文件中读取. 用法:先设定自己的连接参数,在DbConnectionDefaultPool.java文件的loadProperties方法中.注意你也需要设定连接池的log文件的存放位置. String driver="org.gjt.mm.mysql.Driver";//这是使用的JDBC驱动String server="jdbc:mysql://192.100.100.1/qin

一个连接池的例子(来自JIVE)(1)

//文件:DbConnectionDefaultPool.java的第一部分//请注意看里面注明的一处需要修改连接参数的地方package com.qingtuo.db.pool;import java.sql.*;import java.util.*;import java.io.*;import java.text.*;import java.util.Date;/** * Default Jive connection provider. It uses the excellent con

一个连接池的例子(来自JIVE)(6)

//文件:PropertyManager.java //这个类其实没什么用了,可以去掉,但需要去掉前面几个类中对这个类的引用.package com.qingtuo.db.pool; import java.util.*;import java.io.*; /** * Manages properties for the entire Jive system. Properties are merely * pieces of information that need to be saved

一个连接池的例子(来自JIVE)(2)

//文件:DbConnectionDefaultPool.java的第二部分        /**         * Housekeeping thread.  Runs in the background with low CPU overhead.         * Connections are checked for warnings and closure and are periodically         * restarted.         * This thread

一个连接池的例子(来自JIVE)(4)

//文件:DbConnectionManager.javapackage com.qingtuo.db.pool;import java.sql.*;import java.io.*;import java.util.*;/** * Central manager of database connections. */public class DbConnectionManager {    private static DbConnectionProvider connectionProvid

一个连接池的例子(来自JIVE)(3)

//文件:DbConnectionDefaultPool.java的第三部分        /**         * Returns the age of a connection -- the time since it was handed out to         * an application.         */        public long getAge(Connection conn) { // Returns the age of the connection

一个连接池的例子 (一)

//文件:DbConnectionDefaultPool.java的第一部分 //请注意看里面注明的一处需要修改连接参数的地方package com.qingtuo.db.pool; import java.sql.*;import java.util.*;import java.io.*;import java.text.*;import java.util.Date; /** * Default Jive connection provider. It uses the excellent

一个连接池的例子 (二)

        /**         * This method hands out the connections in round-robin order.         * This prevents a faulty connection from locking         * up an application entirely.  A browser 'refresh' will         * get the next connection while the fau

java 需要做一个连接池。但是不是数据库的,而是类似于一个接口(或者IP地址)

问题描述 java 需要做一个连接池.但是不是数据库的,而是类似于一个接口(或者IP地址) 具体场景如下: 对方提供多个计算服务器供我来调用,计算服务器只能同时计算2个任务. 现在我需要将计算服务器做成可以配置的,然后将任务排队.根据先进先出的原则. 如果所有服务器都在计算任务了.剩下的任务就需要排队了.而计算完成后,在去任务池中取任务.直到任务池的所有任务都处理玩了. 解决方案 使用JDK的线程池[Executors#newFixedThreadPool(2) ],同时并行两个任务,其他的都在