当前位置: 首页 > 编程日记 > 正文

c3p0连接池用法

使用连接池的时候并不是在代码中不用获取/释放数据库连接,而是在代码中向连接池申请/释放连接,对于代码而言,可以把连接池看成数据库。

换句话说,连接池就是数据库的代理,之所以要使用这个代理是因为直接向数据库申请/释放连接是要降低性能的:如果每一次数据访问请求都必须经历建立数据库连接、打开数据库、存取数据和关闭数据库连接等步骤,而连接并打开数据库是一件既消耗资源又费时的工作,那么频繁发生这种数据库操作时,系统的性能必然会急剧下降。
连接池的作用是自己维护数据库连接,数据库连接池的主要操作如下:
  (1)建立数据库连接池对象(服务器启动)。
  (2)按照事先指定的参数创建初始数量的数据库连接(即:空闲连接数)。
  (3)对于一个数据库访问请求,直接从连接池中得到一个连接。如果数据库连接池对象中没有空闲的连接,且连接数没有达到最大(即:最大活跃连接数),创建一个新的数据库连接。
  (4)存取数据库。
  (5)关闭数据库,释放所有数据库连接(此时的关闭数据库连接,并非真正关闭,而是将其放入空闲队列中。如实际空闲连接数大于初始空闲连接数则释放连接)。
  (6)释放数据库连接池对象(服务器停止、维护期间,释放数据库连接池对象,并释放所有连接)。

从连接池获取的连接connection跟JDK中的connection有点不同,前者的close方法并没有关闭与数据库的连接,而是将连接返回到池中,这样就可以复用了。如果不调用close方法的话拿就失去了使用连接池的意义了。

开源连接池有很多:DBCP、C3P0、Proxool 、 BoneCP等

C3P0是一个开放源代码的JDBC连接池,它在lib目录中与Hibernate一起发布,包括了实现jdbc3和jdbc2扩展规范说明的Connection 和Statement 池的DataSources 对象。

  1. 下载c3p0的jar,并添加log4j.jar.
  2. 采用ThreadLocal线程局部变量保证线程安全.

使用连接池和不使用连接池时的性能差异简单的C3P0使用测试示例

package com.lnbdqn;import java.beans.PropertyVetoException;
import java.sql.Connection;
import java.sql.SQLException;
import com.mchange.v2.c3p0.ComboPooledDataSource;public final class ConnectionManager {private static ConnectionManager instance;private static ComboPooledDataSource dataSource;private ConnectionManager() throws SQLException, PropertyVetoException {dataSource = new ComboPooledDataSource();dataSource.setUser("loux");dataSource.setPassword("loux");dataSource.setJdbcUrl("jdbc:oracle:thin:@192.168.100.70:1521:orcl");dataSource.setDriverClass("oracle.jdbc.driver.OracleDriver");dataSource.setInitialPoolSize(5);dataSource.setMinPoolSize(1);dataSource.setMaxPoolSize(10);dataSource.setMaxStatements(50);dataSource.setMaxIdleTime(60);}public static final ConnectionManager getInstance() {if (instance == null) {try {instance = new ConnectionManager();} catch (Exception e) {e.printStackTrace();}}return instance;}public synchronized final Connection getConnection() {Connection conn = null;try {conn = dataSource.getConnection();} catch (SQLException e) {e.printStackTrace();}return conn;}
}
package com.lnbdqn;import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;import oracle.jdbc.pool.OracleDataSource;public class ConnectionDemo {public static void main(String[] args) throws SQLException {System.out.println("使用连接池................................");for (int i = 0; i < 20; i++) {long beginTime = System.currentTimeMillis();Connection conn = ConnectionManager.getInstance().getConnection();try {PreparedStatement pstmt = conn.prepareStatement("SELECT * FROM t_fmscpy200");ResultSet rs = pstmt.executeQuery();while (rs.next()) {}} catch (SQLException e) {e.printStackTrace();} finally {try {conn.close();} catch (SQLException e) {e.printStackTrace();}}long endTime = System.currentTimeMillis();System.out.println("第" + (i + 1) + "次执行花费时间为:" + (endTime - beginTime));}System.out.println("不使用连接池................................");for (int i = 0; i < 20; i++) {long beginTime = System.currentTimeMillis();OracleDataSource ods = new OracleDataSource();ods.setUser("loux");ods.setPassword("loux");ods.setURL("jdbc:oracle:thin:@192.168.100.70:1521:orcl");Connection conn = ods.getConnection();try {PreparedStatement pstmt = conn.prepareStatement("SELECT * FROM table_name");ResultSet rs = pstmt.executeQuery();while (rs.next()) {// do nothing...
                }} catch (SQLException e) {e.printStackTrace();} finally {try {conn.close();} catch (SQLException e) {e.printStackTrace();}}long endTime = System.currentTimeMillis();System.out.println("第" + (i + 1) + "次执行花费时间为:"+ (endTime - beginTime));}}
}
控制台输出的结果为:使用连接池................................
第1次执行花费时间为:1469
第2次执行花费时间为:0
第3次执行花费时间为:16
第4次执行花费时间为:0
第5次执行花费时间为:0
第6次执行花费时间为:15
第7次执行花费时间为:0
第8次执行花费时间为:0
第9次执行花费时间为:0
第10次执行花费时间为:0
第11次执行花费时间为:16
第12次执行花费时间为:0
第13次执行花费时间为:0
第14次执行花费时间为:0
第15次执行花费时间为:0
第16次执行花费时间为:16
第17次执行花费时间为:0
第18次执行花费时间为:0
第19次执行花费时间为:15
第20次执行花费时间为:0
不使用连接池................................
第1次执行花费时间为:47
第2次执行花费时间为:31
第3次执行花费时间为:32
第4次执行花费时间为:46
第5次执行花费时间为:32
第6次执行花费时间为:31
第7次执行花费时间为:47
第8次执行花费时间为:31
第9次执行花费时间为:47
第10次执行花费时间为:31
第11次执行花费时间为:47
第12次执行花费时间为:31
第13次执行花费时间为:32
第14次执行花费时间为:46
第15次执行花费时间为:47
第16次执行花费时间为:32
第17次执行花费时间为:46
第18次执行花费时间为:47
第19次执行花费时间为:32
第20次执行花费时间为:31
可以看出,在使用连接池时,第一次执行花费的时间稍长,因为第一次初始化操作需要创建多个连接并放入池中,以后使用时将会大大缩短执行时间。
在不使用连接池时,每次花费的时间都比较长。

下面是一个service层的银行转账方法

    public void transferMoneyNew(int from,int to,float money) throws Exception{AccountDAOImpl dao = null;try{/*完成的功能:1.从数据源中获取Connection2.开启事务3. 放到线程上*/JDBCUtils.startTransaction();  //创建DAOdao = new AccountDAOImpl();     //获取账户信息Account fromAccount = dao.findAccountByID(from);Account toAccount = dao.findAccountByID(to);//扣钱和加钱fromAccount.setMoney(fromAccount.getMoney() - money);toAccount.setMoney(toAccount.getMoney() + money);        //更新数据库
            dao.updateAccount(fromAccount);       //产生错误int i=1/0;       dao.updateAccount(toAccount);        //提交
            JDBCUtils.commit();}catch(Exception ex){JDBCUtils.rollback();throw new ServiceException(ex);}finally{JDBCUtils.release();}}

JDBCUtils类
public class JDBCUtils {//连接的容器public static ThreadLocal<Connection> container = new ThreadLocal<Connection>();//定义c3p0 数据源private static DataSource ds = new ComboPooledDataSource();/*完成的功能:1.从数据源中获取Connection2.开启事务3. 放到线程上*/public static void startTransaction() throws SQLException{Connection conn  = container.get();//当前线程上是否已经存在连接if(conn == null){conn = ds.getConnection();}//开启事务conn.setAutoCommit(false);//放到当前线程上
        container.set(conn);}//提交当前线程上的连接public static void commit() throws SQLException{Connection conn  = container.get();if(conn != null){conn.commit();}}//回滚当前线程上的连接public static void  rollback() throws SQLException{Connection conn  = container.get();if(conn != null){conn.rollback();}}//释放当前线程上的连接public static void release() throws SQLException{Connection conn  = container.get();if(conn != null){//从当前线程上,拿掉连接
            container.remove();conn.close();}        }//返回数据源public static DataSource getDataSource(){return ds;}public static Connection getConnection() throws SQLException {return ds.getConnection();}//释放资源public static void release(Connection conn,Statement st,ResultSet rs){if(rs != null){try {rs.close();} catch (SQLException e) {throw new RuntimeException(e);}finally{rs = null;}}   if(st != null){try {st.close();} catch (SQLException e) {throw new RuntimeException(e);}finally{st = null;}}if(conn != null){try {conn.close();} catch (SQLException e) {throw new RuntimeException(e);}finally{conn = null;}}        }
}

OSChina 的 DBManager 类 管理数据库连接

public class DBManager {private final static Log log = LogFactory.getLog(DBManager.class);private final static ThreadLocal<Connection> conns = new ThreadLocal<Connection>();private static DataSource dataSource;private static boolean show_sql = false;static {initDataSource(null);}/*** 初始化连接池* @param props* @param show_sql*/private final static void initDataSource(Properties dbProperties) {try {if(dbProperties == null){dbProperties = new Properties();dbProperties.load(DBManager.class.getResourceAsStream("db.properties"));}Properties cp_props = new Properties();for(Object key : dbProperties.keySet()) {String skey = (String)key;if(skey.startsWith("jdbc.")){String name = skey.substring(5);cp_props.put(name, dbProperties.getProperty(skey));if("show_sql".equalsIgnoreCase(name)){show_sql = "true".equalsIgnoreCase(dbProperties.getProperty(skey));}}}dataSource = (DataSource)Class.forName(cp_props.getProperty("datasource")).newInstance();if(dataSource.getClass().getName().indexOf("c3p0")>0){//Disable JMX in C3P0System.setProperty("com.mchange.v2.c3p0.management.ManagementCoordinator", "com.mchange.v2.c3p0.management.NullManagementCoordinator");}log.info("Using DataSource : " + dataSource.getClass().getName());BeanUtils.populate(dataSource, cp_props);Connection conn = getConnection();DatabaseMetaData mdm = conn.getMetaData();log.info("Connected to " + mdm.getDatabaseProductName() + " " + mdm.getDatabaseProductVersion());closeConnection();} catch (Exception e) {throw new DBException(e);}}/*** 断开连接池*/public final static void closeDataSource(){try {dataSource.getClass().getMethod("close").invoke(dataSource);} catch (NoSuchMethodException e){ } catch (Exception e) {log.error("Unabled to destroy DataSource!!! ", e);}}public final static Connection getConnection() throws SQLException {Connection conn = conns.get();if(conn ==null || conn.isClosed()){conn = dataSource.getConnection();conns.set(conn);}return (show_sql && !Proxy.isProxyClass(conn.getClass()))?new _DebugConnection(conn).getConnection():conn;}/*** 关闭连接*/public final static void closeConnection() {Connection conn = conns.get();try {if(conn != null && !conn.isClosed()){conn.setAutoCommit(true);conn.close();}} catch (SQLException e) {log.error("Unabled to close connection!!! ", e);}conns.set(null);}/*** 用于跟踪执行的SQL语句* @author Winter Lau*/static class _DebugConnection implements InvocationHandler {private final static Log log = LogFactory.getLog(_DebugConnection.class);private Connection conn = null;public _DebugConnection(Connection conn) {this.conn = conn;}/*** Returns the conn.* @return Connection*/public Connection getConnection() {return (Connection) Proxy.newProxyInstance(conn.getClass().getClassLoader(), conn.getClass().getInterfaces(), this);}public Object invoke(Object proxy, Method m, Object[] args) throws Throwable {try {String method = m.getName();if("prepareStatement".equals(method) || "createStatement".equals(method))log.info("[SQL] >>> " + args[0]);                return m.invoke(conn, args);} catch (InvocationTargetException e) {throw e.getTargetException();}}}}
# DataSource
jdbc.datasource=com.mchange.v2.c3p0.ComboPooledDataSource
jdbc.show_sql=true# Database Configurations
jdbc.driverClass=com.mysql.jdbc.Driver
jdbc.jdbcUrl=jdbc:mysql://localhost:3306/oscdb
jdbc.user=root
jdbc.password=xxxx
jdbc.maxPoolSize=100
jdbc.minPoolSize=2
jdbc.initialPoolSize=2
jdbc.acquireIncrement=2
jdbc.maxStatements=1000
jdbc.maxIdleTime=300
jdbc.checkoutTimeout=5000

参数配置例子

package com.wb.db;
import java.beans.PropertyVetoException;
import java.sql.Connection;
import java.sql.SQLException;
import javax.sql.DataSource;
import com.mchange.v2.c3p0.ComboPooledDataSource;
/**
* 采用ThreadLocal线程局部变量保证线程安全
* @author hemes1314
*/
public class C3p0Pool {public static ThreadLocal connectionHolder = new ThreadLocal(); private static DataSource dataSource;public C3p0Pool(){   }   public static Connection getConnection() {Connection conn = (Connection) connectionHolder.get();//如果在当前线程中没有绑定相应的Connectionif(conn==null){if (dataSource == null) {   initDataSource();}   try {   conn = dataSource.getConnection(); //将Connection设置到ThreadLocal线程变量中
             connectionHolder.set(conn); } catch (SQLException e) {   // TODO Auto-generated catch block   
             e.printStackTrace();   } }return conn;   }public static void closeConnection(){Connection conn = (Connection) connectionHolder.get();if(conn!=null){try {conn.close();//从ThreadLocal中清除Connection
     connectionHolder.remove();} catch (SQLException e) {// TODO Auto-generated catch block
     e.printStackTrace();}}}public static void initDataSource(){   String driverClassName=null;   String url=null;   String username=null;   String password=null;   int initialPoolSize=3;   int maxPoolSize=15;int minPoolSize=5;int acquireRetryDelay=1000;int maxIdleTime=60;Configuration config=new Configuration("oraConn.properties");driverClassName = config.getValue("driver");   url = config.getValue("url");username = config.getValue("user");password = config.getValue("password");   initialPoolSize = Integer.parseInt(config.getValue("initialPoolSize").trim());       maxPoolSize = Integer.parseInt(config.getValue("maxPoolSize").trim());minPoolSize = Integer.parseInt(config.getValue("minPoolSize").trim());maxIdleTime = Integer.parseInt(config.getValue("maxIdleTime").trim()); ComboPooledDataSource cpds = new ComboPooledDataSource();    try {cpds.setDriverClass(driverClassName);} catch (PropertyVetoException e) {// TODO Auto-generated catch block
    e.printStackTrace();}cpds.setUser(username);   cpds.setPassword(password);   cpds.setJdbcUrl(url);//初始化时获取三个连接,取值应在minPoolSize与maxPoolSize之间。Default: 3 initialPoolSize   
    cpds.setInitialPoolSize(initialPoolSize);   //连接池中保留的最大连接数。Default: 15 maxPoolSize   
    cpds.setMaxPoolSize(maxPoolSize);//连接池中保留的最小连接数。   
    cpds.setMinPoolSize(minPoolSize);//获得连接的最大等待毫秒数。Default: 1000 acquireRetryDelay
    cpds.setAcquireRetryDelay(acquireRetryDelay);//最大空闲时间,60秒内未使用则连接被丢弃。若为0则永不丢弃。Default: 0 maxIdleTime   
    cpds.setMaxIdleTime(maxIdleTime);//当连接池中的连接耗尽的时候c3p0一次同时获取的连接数。Default: 3 acquireIncrement   //cpds.setAcquireIncrement(3);   //每60秒检查所有连接池中的空闲连接。Default: 0 idleConnectionTestPeriod   //cpds.setIdleConnectionTestPeriod(60);//连接关闭时默认将所有未提交的操作回滚。Default: false autoCommitOnClose   //cpds.setAutoCommitOnClose(true);//JDBC的标准参数,用以控制数据源内加载的PreparedStatements数量。但由于预缓存的statements属于单个connection而不是整个连接池。所以设置这个参数需要考虑到多方面的因素。如果maxStatements与maxStatementsPerConnection均为0,则缓存被关闭。Default: 0 //cpds.setMaxStatements(1);//maxStatementsPerConnection定义了连接池内单个连接所拥有的最大缓存statements数//cpds.setMaxStatementsPerConnection(100);//定义所有连接测试都执行的测试语句。在使用连接测试的情况下这个一显著提高测试速度。注意:测试的表必须在初始数据源的时候就存在。Default: null preferredTestQuery   //cpds.setPreferredTestQuery("select sysdate from dual");   // 因性能消耗大请只在需要的时候使用它。如果设为true那么在每个connection提交的   // 时候都将校验其有效性。建议使用idleConnectionTestPeriod或automaticTestTable   // 等方法来提升连接测试的性能。Default: false testConnectionOnCheckout   //cpds.setTestConnectionOnCheckout(true);//如果设为true那么在取得连接的同时将校验连接的有效性。Default: false testConnectionOnCheckin   //cpds.setTestConnectionOnCheckin(true);   //定义在从数据库获取新连接失败后重复尝试的次数。Default: 30 acquireRetryAttempts   //cpds.setAcquireRetryAttempts(30);     //获取连接失败将会引起所有等待连接池来获取连接的线程抛出异常。但是数据源仍有效   //保留,并在下次调用getConnection()的时候继续尝试获取连接。如果设为true,那么在尝试   //获取连接失败后该数据源将申明已断开并永久关闭。Default: false breakAfterAcquireFailure   //cpds.setBreakAfterAcquireFailure(false);   dataSource = cpds;        }/* 用于测试连接状态的方法*/public static void main(String[] args) {ComboPooledDataSource ds=(ComboPooledDataSource)dataSource;   try {System.out.println(ds.getConnection());} catch (SQLException e) {// TODO Auto-generated catch block
    e.printStackTrace();}//System.out.println(ds.getInitialSize());   //System.out.println(ds.getNumActive());   //System.out.println(ds.getNumIdle());   //System.out.println(ds.getDefaultAutoCommit());
}}

转载于:https://www.cnblogs.com/janko208/archive/2012/08/27/2658628.html

相关文章:

我所理解的字符编码

1&#xff0c;Ascii和ebcic. 为了方便交流&#xff0c;美国人发明了ASCII编码&#xff0c;后来被确认为国际标准。后来以发明了EBCDIC编码。 一般地说&#xff0c;开放的操作系统&#xff08;LINUX 、WINDOWS等&#xff09;采用ASCII 编码&#xff0c;而大型主机系统&#xff0…

void函数调用时显示不允许使用不完整的_C语言的角落——这些C语言不常用的特性你知道吗?...

变长参数列表头文件定义了一些宏&#xff0c;当函数参数未知时去获取函数的参数变量&#xff1a;typedef va_list宏&#xff1a;va_start()va_arg()va_end()va_list类型通过stdarg宏定义来访问一个函数的参数表&#xff0c;参数列表的末尾会用省略号省略 (va_list用来保存va_st…

centos下为firefox安装flash插件的几种方法

首先去官网去下载RPM格式的安装包&#xff0c;比如&#xff1a;flash-plugin-11.1.102.55-release.i386.rpm&#xff0c;默认下载位置是该用户的下载文件夹。 方法一&#xff1a;用gnome 双击该文件&#xff0c;按提示操作即可。 方法二&#xff1a;命令行&#xff0c;在该文件…

eoLinker AMS 专业版V3.3发布:分享项目可以测试并选择分享内容等

eoLinker AMS是集API文档管理、API自动化测试、开发协作三位一体的综合API开发管理平台&#xff0c;是中国最大的在线API管理平台。目前eoLinker AMS已经为来自全球的超过两万家企业托管超过一百万的API&#xff0c;我们感谢每个曾经以及正在支持我们的企业以及开发者朋友&…

MyBatis基础-CRUD

一、mybatis 环境搭建步骤 第一步&#xff1a;创建 maven 工程第二步&#xff1a;导入坐标第三步&#xff1a;编写必要代码&#xff08;实体类和持久层接口&#xff09;第四步&#xff1a;编写 SqlMapConfig.xml第五步&#xff1a;编写映射配置文件第六步&#xff1a;编写测…

python答题系统的代码_Python考试系统自动答题(教务处)

要求 某学校要求登录教务处网站 做一个测试题 30分钟300道题&#xff0c;240分几个&#xff0c;题量不少&#xff0c;题还不好做。 研究发现原来在网站上有题库 但是一道题只有6s 的时间作答 边查边做时间不够 人生苦短&#xff0c;何不Python当歌&#xff1f; 来个自动答题的智…

((ios开发学习笔记九)) Simple TableView 实现(附 实例源码)

实现效果&#xff1a; 实现过程&#xff1a; Step One 创建单个窗体项目 Step Two 创建control 接口 Step Three 创建窗体和关联关系 Step four 实现table view 的接口 control 初始化选择数据 实现Data Source 部分 实现TableView委托部分 源码下载 TestTableView.zip转载于:…

24个为Web开发人员准备的CSS3实用教程

本文搜集了一些关于CSS3的最新教程。你可以根据这些教程或技术来实现网页设计&#xff0c;包括&#xff1a;文字阴影、圆角框、盒模型尺寸计算&#xff08;box sizing&#xff09;、透明效果处理、多重背景、边框图像等。以下这些都是非常实用的CSS3教程&#xff0c;提供了许多…

前端基础之JQuery

一、什么是JQuery &#xff3b;1&#xff3d; jQuery由美国人John Resig创建&#xff0c;至今已吸引了来自世界各地的众多 javascript高手加入其team。 &#xff3b;2&#xff3d; jQuery是一种新型的JavaScript库。jq是用js写的&#xff0c;能用jq实现&#xff0c;用js都能…

测试linux下磁盘的读写速率

1&#xff09; 通过df -h命令查看磁盘情况Filesystem Size Used Avail Use% Mounted on/dev/sda4 289G 61G 214G 23% /tmpfs 7.8G 0 7.8G 0% /dev/shm/dev/sda2 969M 62M 857M 7% /boot/dev/sda1 …

multipart request_Request和Response

Response讲解7.1 Response简介定义辅助 servlet 将响应发送到客户端的对象。servlet 容器创建 ServletResponse 对象&#xff0c;并将它作为参数传递给 servlet 的 service 方法。 要发送 MIME 正文响应中的二进制数据&#xff0c;请使用 #getOutputStream 返回的 ServletOutpu…

SharePoint 客户端经常弹出Windows验证登录框问题

场景描述&#xff1a; Site工作人员UserA创建了一个Task&#xff0c;并且Assign给UserB。UserB接到来自Task List的邮件通知。这时UserA发现Assign的人错了&#xff0c;重新修改Task Item&#xff0c;将任务重新Assign给另外一个用户UserC&#xff0c;并且同时收回了UserB的访问…

SkFlattenable /Registrar/

/** \class SkFlattenableSkFlattenable is the base class for objects that need to be flattenedinto a data stream for either transport or as part of the key to thefont cache.*/ class SK_API SkFlattenable : public SkRefCnt {}以SkFlattenable为基类的对象是&…

启动 ServiceFabric Windows服务报1053

Remote Procedure Call (RPC) Locator和 Windows Firewall是否启动。 以管理员身份运行PowerShell&#xff0c;输入Unregister-ScheduledTask FabricCounters&#xff0c;然后输入Y。 到这一步基本OK了 右下角reset sf后查看是否存在 X:\SfDevCluster\Data\ImageStoreShare 文件…

Spring基础面试题(一)

Spring是什么&#xff1f;Spring是一个轻量级的IoC和AOP容器框架。是为Java应用程序提供基础性服务的一套框架&#xff0c;目的是用于简化企业应用程序的开发&#xff0c;它使得开发者只需要关心业务需求。常见的配置方式有三种&#xff1a;基于XML的配置、基于注解的配置、基于…

C#线程间操作无效: 从不是创建控件 XX 的线程访问它

转自&#xff1a;http://www.arasplm.net/index.php/zh/community/myblog/c-xx-.html 前些天做的要使用到线程的项目&#xff0c;现在和大家分享一下感受&#xff01; 以下面小列子为例&#xff0c;给出这个问题的解决办法。下面的列子是以一个计数器为列讲解的。 public Form1…

boost安装_【环境搭建】源码安装Boost

写C的话boost是必不可少的&#xff0c;本文将boost的安装过程用写成脚本&#xff0c;直接一行命令解决整个编译安装过程&#xff1a;sudo bash boost-linux-installer.sh下面是boost-linux-installer.sh的内容&#xff1a;#!/usr/bin/env bash

css新闻列表优化-突破思维新方法更利于搜索引擎

效果图如下&#xff1a; 也许你会认为这个是很简单的&#xff0c;呵呵那是因为一般写这个列表的时候用的都是时间写在前面&#xff0c;标题写在后面&#xff0c;那样对于显示来说是先有时间后有标题的&#xff0c;对搜索引擎不是很友好。 老方法大概是这样的&#xff1a; html代…

STL使用记录

1&#xff0c;map 对map实在不熟。。。赶紧记录一下用法吧。 后来再发现新的用法再补充吧 定义&#xff1a; map<int, int> m; 其中的int可以为自定义的任何类型。 m[key值类型的变量] value值&#xff1b; 但是注意如果key值是自定义的结构体的话&#xff0c;一定要重载…

Linux tcpdump命令详解与Wireshark

简介 用简单的话来定义tcpdump&#xff0c;就是&#xff1a;dump the traffic on a network&#xff0c;根据使用者的定义对网络上的数据包进行截获的包分析工具。 tcpdump可以将网络中传送的数据包的“头”完全截获下来提供分析。它支持针对网络层、协议、主机、网络或端口的过…

dubbo yml配置_利用springboot+dubbo,构建分布式微服务,全程注解开发(一)

随着互联网的发展&#xff0c;网站应用的规模不断扩大&#xff0c;常规的垂直应用架构已无法应对&#xff0c;分布式服务架构以及流动计算架构势在必行&#xff0c;亟需一个治理系统确保架构有条不紊的演进。一、先来一张图说起 Dubbo&#xff0c;相信大家都不会陌生&#xff0…

treeview 保持选中状态

发现当treeview控件失去焦点的时候&#xff0c;会丢失选中状态的指示&#xff08;条目的蓝色背景&#xff09;。如果想要保持&#xff0c;只要设置treeview的一个属性即可&#xff1a; this.treeView1.HideSelection false; 但是&#xff0c;发现阴影很浅&#xff0c;但是聊胜…

1-2-Active Directory 域服务准备概述

参照: http://technet.microsoft.com/zh-cn/library/gg398869.aspx Active Directory 域服务准备概述 上一次修改主题&#xff1a; 2010-12-09 要为 Microsoft Lync Server 2010 部署准备 Active Directory 域服务 (AD DS)&#xff0c;必须按照特定顺序执行三个步骤。 下表介绍…

iOS----------拨打电话的3种方式

iOS实现拨打电话的方式&#xff1a;方法一、requestWithURL&#xff0c;此方法拨打前弹出提示NSMutableString * string [[NSMutableString alloc] initWithFormat:"tel:%","136****0000"];UIWebView * callWebview [[UIWebView alloc] init];[callWebvi…

linux命令 iperf-网络性能测试工具

iperf命令是一个网络性能测试工具。iperf可以测试TCP和UDP带宽质量。iperf可以测量最大TCP带宽&#xff0c;具有多种参数和UDP特性。iperf可以报告带宽&#xff0c;延迟抖动和数据包丢失。利用iperf这一特性&#xff0c;可以用来测试一些网络设备如路由器&#xff0c;防火墙&am…

SearchHit转成java对象_Java开发中最常犯的10个错误,你中招了吗?

http://www.programcreek.com/2014/05/top-10-mistakes-java-developers-make/阅读目录Array转ArrayList判断一个数组是否包含某个值在循环内部删除List中的一个元素HashTable与HashMap使用集合原始类型(raw type)访问级别ArrayList和LinkedList可变与不可变父类和子类的构造方…

hdu1160FatMouse's Speed(DP)

http://acm.hdu.edu.cn/showproblem.php?pid1160 1A 破题敲了一个多小时 最长上升子序列和最长下降子序列合起来 并把路径保留下来 题中是可以打乱顺序去找的 先按W上升或S下降排下序 再按最升和最降做 View Code 1 #include <iostream>2 #include<cstdio>3 #inc…

五、springcloud之客户端负载均衡Ribbon

一、简介 在微服务架构中&#xff0c;业务都会被拆分成一个独立的服务&#xff0c;服务与服务的通讯是基于http restful的。Spring cloud有两种服务调用方式&#xff1a; 一种是ribbonrestTemplate&#xff0c; 另一种是feign。 ribbon是一个负载均衡客户端&#xff0c;可以很好…

fiddler 抓取winform wcf包

修改客户端配置<system.net> <defaultProxy> <proxy bypassonlocal"false" usesystemdefault"true" /> </defaultProxy> </system.net> 最好使用机器名替换 localhost 2 fiddler 过滤设置 3 查看抓包数据 fiddler 抓包官方说…

dhcp报文_动态地址分配DHCP,IP地址管理方式及分配原则,一分钟了解下

一、DHCP简介DHCP(Dynamic Host Configuration Protocol&#xff0c;动态主机配置协议)用来为网络设备动态地分配 IP地址等网络配置参数。DHCP 采用客户端/服务器通信模式&#xff0c;由客户端向服务器提出请求分配网络配置参数的申请&#xff0c;服务器返回为客户端分配的 IP …