- 浏览: 3470598 次
- 性别:
- 来自: 北京
文章分类
最新评论
-
wanglf1207:
EJB的确是个不错的产品,只是因为用起来有点门槛,招来太多人吐 ...
weblogic-ejb-jar.xml的元素解析 -
qwfys200:
总结的不错。
Spring Web Flow 2.0 入门 -
u011577913:
u011577913 写道也能给我发一份翻译文档? 邮件437 ...
Hazelcast 参考文档-4 -
u011577913:
也能给我发一份翻译文档?
Hazelcast 参考文档-4 -
songzj001:
DbUnit入门实战
Mysql Using Master/Slave Replication with ReplicationConnection
- 博客分类:
- Database
Starting with Connector/J 3.1.7, we've made available a variant of
the driver that will automatically send queries to a read/write master,
or a failover or round-robin loadbalanced set of slaves based on the
state of Connection.getReadOnly()
.
An application signals that it wants a transaction to be read-only by calling Connection.setReadOnly(true)
,
this replication-aware connection will use one of the slave
connections, which are load-balanced per-vm using a round-robin scheme
(a given connection is sticky to a slave unless that slave is removed
from service). If you have a write transaction, or if you have a read
that is time-sensitive (remember, replication in MySQL is asynchronous),
set the connection to be not read-only, by calling Connection.setReadOnly(false)
and the driver will ensure that further calls are sent to the master
MySQL server. The driver takes care of propagating the current state of
autocommit, isolation level, and catalog between all of the connections
that it uses to accomplish this load balancing functionality.
To enable this functionality, use the " com.mysql.jdbc.ReplicationDriver
" class when configuring your application server's connection pool or
when creating an instance of a JDBC driver for your standalone
application. Because it accepts the same URL format as the standard
MySQL JDBC driver, ReplicationDriver
does not currently work with java.sql.DriverManager
-based connection creation unless it is the only MySQL JDBC driver registered with the DriverManager
.
Here is a short, simple example of how ReplicationDriver might be used in a standalone application.
import java.sql.Connection; import java.sql.ResultSet; import java.util.Properties; import com.mysql.jdbc.ReplicationDriver; public class ReplicationDriverDemo { public static void main(String[] args) throws Exception { ReplicationDriver driver = new ReplicationDriver(); Properties props = new Properties(); // We want this for failover on the slaves props.put("autoReconnect", "true"); // We want to load balance between the slaves props.put("roundRobinLoadBalance", "true"); props.put("user", "foo"); props.put("password", "bar"); // // Looks like a normal MySQL JDBC url, with a // comma-separated list of hosts, the first // being the 'master', the rest being any number // of slaves that the driver will load balance against // Connection conn = driver.connect("jdbc:mysql://master,slave1,slave2,slave3/test", props); // // Perform read/write work on the master // by setting the read-only flag to "false" // conn.setReadOnly(false); conn.setAutoCommit(false); conn.createStatement().executeUpdate("UPDATE some_table ...."); conn.commit(); // // Now, do a query from a slave, the driver automatically picks one // from the list // conn.setReadOnly(true); ResultSet rs = conn.createStatement().executeQuery("SELECT a,b FROM alt_table"); ....... } }
You may also want to investigate the Load Balancing JDBC Pool (lbpol) tool, which provides a wrapper around the standard JDBC driver and allows you to use DB connection pools that includes checks for system failures and uneven load distribution. For more information, see Load Balancing JDBC Pool (lbpool) .
发表评论
-
oracle复制表数据,复制表结构
2011-07-25 21:19 361331.不同用户之间的表数据复制 对于在一个数据库上的两个 ... -
删除 SQL Server 的所有已知实例
2011-04-05 18:42 1997如果提示实例已经被注册,无法安装,那么: 删除 SQL ... -
【SQL】安装 SQL SERVER MsiGetProductInfo 无法检索 Product Code 1605错误 解决方案
2011-04-05 17:10 4802重装数据库服务器上的SQL SERVER 2008 上遇到了以 ... -
oracle网络配置listener.ora、sqlnet.ora、tnsnames.ora
2010-12-03 12:36 33293oracle网络配置 三个配置文件 listener.ora ... -
Oracle XE的数据库创建过程
2010-12-02 22:55 4286今天安装了Oracle XE,发现并没有自动创建数据库。趁着 ... -
实现数据库TPC性能测试的开源及商业软件
2010-12-02 01:11 3092商业软件 Benchmark Factory ... -
MySQL压力测试工具mysqlslap
2010-11-07 17:13 1735MySQL从5.1.4版开始带有一个压力测试工具mys ... -
一台机器上安装多个mysqld实例
2010-11-06 16:09 2124一台机器安装多个mysqld实例 1. ps -aux | ... -
MySQL数据库双向同步
2010-08-25 20:23 40281. 主从关系的同步 master端 192.168.5 ... -
MySQL 数据库之间的同步(windows与linux)
2010-08-25 20:14 31561.导出windows mysql的test库到linux m ... -
Ubuntu Server 下开启远程连接 MySQL
2010-03-16 23:24 3073要通过远程连接MySQL,需要做两步:第一步是要创建一个可以远 ... -
DB2 在REDHAT 5下的详细安装过程 DB2 9.5 C EXPRESS
2010-03-02 10:43 4533过详细测试并且补充后发表, 括号内的为自行添加的内容. ... -
IBM DB2 Express-C 9.5.2
2010-03-02 09:44 3468或许您已经知 ... -
Oracle Database 10g Express Edition安装小结
2010-03-01 15:28 9130racle Database 10g Express Edit ... -
HA JDBC – High Availability JDBC
2010-02-27 18:46 3280Some time ago I worked on a pr ... -
数据归档将走向何方
2010-02-25 11:50 2240数据量的爆炸性增长,让我们不得不更加关心存储。这也造成 ... -
Database
2010-02-18 15:53 2281下一代数据库发展的4大趋势 趋势之一:对XML的支 ... -
免安装Oracle运行pl/sql developer
2010-02-16 20:27 2159Sql客户端中,虽然最便捷的是万能而且轻量无比的Sql Wor ... -
在debian上安装oracle 10g express
2010-02-16 18:46 4881在debian上安装oracle 10g express 若 ... -
Oracle 数据库 10g 特别版:并非只适合初学者
2010-02-16 17:24 2038作者:Lewis Cunningham ...
相关推荐
Master-Slave的数据库机构解决了很多问题,特别是read/write比较高的web2.0应用: 1、写操作全部在Master结点执行,并由Slave数据库结点定时(默认60s)读取Master的bin-log 2、将众多的用户读请求分散到更多的...
mysql master-slave 主从配置的讲解
用于指导部署activemq master/slave架构,采用NFS
Arduino上的MODBUS库,可与PLC等进行MODBUS通讯
i2s串行线广泛用于音频通信中,这里包括了master和slave的代码.
Xilinx提供的I2C控制器代码,Master/Slave全功能
The devices embed four universal synchronous/asynchronous receiver transmitters (USART1, USART2, USART3 and USART6) and four universal asynchronous receiver ...have LIN Master/Slave capability.
F00x_SPI0_EEPROM_Polled_Mode/F00x_SPI0_Master/F00x_SPI0_Slave c source code that can be applied to C8051f00x
master slave tx_rx code master for cc2500
主要介绍了mysql(master/slave)主从复制原理及配置图文详解,以前脚本之家小编发过相关的内容,但这么好的非常少见特分享一下,需要的朋友可以参考下
使用allen老师的hub镜像制作自己的mysql主从 --------- docker pull xiaochunping/mysql-master;...slave配置文件/home/mysql/etc/slave/slave.cnf mkdir -p /home/mysql/master-data mkdir -p /home/mysql/slave-data
verilog实现axis接口读写I2C,代码中包含master/slave两部分 master: axis to I2C slave : I2C to axis
Building Automation House Control with LOGO! 8 and Master-Slave Communication (LOGO! Set 9)
axi协议的vip,包括master和slave
cypress gpif config code,auto mode,include master and slave mode.
this is the wishbone master interface to connect with wishbone slave and a clock module
ARM Keil I2C Peripheral
主从多机通信系统问题研究建模即其可靠性研究