proxysql官方推荐两种高可用方案:

1、MHA+proxysql

2、mysqlrpladmin+proxysql

MySQLfailover工具包含在mysqlrpladmin工具中,所以两者可以相互替换。

mysqlfailover+proxysql做读写分离和高可用。现在生产环境中也是这一套。

MySQLfailover和proxysql都是非常灵活的两个中间件,可以相互配合使用。

如果是链式复制,也就是master-->slave-->slave,那么也可以用MySQLfailover+proxysql进行读写分离和高可用。

如果业务量增大,可以考虑PXC或MariaDB的Galera集群。

mysql官方的集群方案:mysql cluster、MGR,两者的业务限制比较严格,只适合于对主键严重依赖且没有大事物的环境中。

如果只需要执行查询的数据库,那么可以在生产环境中用percona的tokudb引擎。

前提:

mysqlfailover需要GTID复制。

proxysql需要:yum install -y perl-DBD-MySQL perl-DBI perl-Time-HiRes perl-IO-Socket-SSL

添加好程序账号(failover),故障转移账号(failover),proxysql心跳检测账号(monitor),这里测试图方便所以程序账号和故障转移账号用一个了。

规划:

master:192.168.0.106

slave:192.168.0.109

slave:192.168.0.112

proxysql:192.168.0.111

部署好mysql服务。在proxysql机器上安装好mysql。

两台从机都连接到192.168.0.106上。

一、配置proxysql:

主要配置有4张表:mysql_servers,mysql_users,mysql_query_rules,mysql_replication_hostgroups

1:mysql_servers,这张表用来添加后端mysql实例的表。

insert into mysql_servers(hostgroup_id,hostname,port,weight,comment) values('1','192.168.0.106','3306',1,'Write Group');  这里设置1位写组
insert into mysql_servers(hostgroup_id,hostname,port,weight,comment) values('2','192.168.0.109','3306',1,'Read Group');  这里设置2为读组

insert into mysql_servers(hostgroup_id,hostname,port,weight,comment) values('2','192.168.0.112','3306',1,'Read Group');

2:mysql_users,这张表用来设置程序账号的,需要提前在两台mysql上添加。

insert into mysql_users(username,password,active,default_hostgroup,transaction_persistent) values('failover','123456',1,1,1);  这里图方便,MySQLfailover和proxysql用一个账号了,生产环境中不能这么做。

3:设置proxysql心跳检测账号:

set mysql-monitor_username='monitor'; set mysql-monitor_password='123456';

4:mysql_query_rules,路由表,用来配置分发的,也就是读写分离规则。

INSERT INTO mysql_query_rules(active,match_pattern,destination_hostgroup,apply) VALUES(1,'^SELECT.*FOR UPDATE$',1,1);  
INSERT INTO mysql_query_rules(active,match_pattern,destination_hostgroup,apply) VALUES(1,'^SELECT',2,1);

5:mysql_replication_hostgroups,用来配置高可用的,

mysql_replication_hostgroups中的每一行代表一对writer_hostgroup和reader_hostgroup。ProxySQL将监视read_only指定主机组中所有服务器的值,并根据值read_only将服务器分配给编写器或读取器主机组。字段注释可用于存储任意数据。

这些字段具有以下语义:

  • writer_hostgroup- 默认情况下将发送所有流量的主机组,read_only=0MySQL中的节点将分配给此主机组。
  • reader_hostgroup- 应该将读取流量的主机组发送到,应该定义查询规则或单独的只读用户将流量路由到此主机组,这些节点read_only=1将分配给该主机组。
  • comment - 可用于用户定义的任何目的的文本字段。可以是群集存储内容的描述,添加或禁用主机组的提醒,或某些检查器脚本处理的JSON。

以上是官方文档说明,意思是说用read_only变量来检测主机变化,从而实现高可用。表有3个字段,设置前面设置好的读写组的ID,插入到这张表里。

insert into  mysql_replication_hostgroups (writer_hostgroup,reader_hostgroup,comment)values('1','2','高可用');

最后,要加载到runtime模块中使其生效,然后再保存到硬盘中。

mysql -uadmin -padmin -h 127.0.0.1 -P 6032 -e "load mysql servers to runtime;load mysql users to runtime;load mysql variables to runtime;LOAD MYSQL QUERY RULES TO RUNTIME;save mysql servers to disk;save mysql users to disk;save mysql variables to disk;SAVE MYSQL QUERY RULES TO DISK;"

二、MySQLfailover

具体的MySQLfailover工具可以在:

https://www.cnblogs.com/magmell/p/9570743.html

https://www.cnblogs.com/magmell/p/9257935.html  找到安装方法。

运行:

mysqlfailover --master=failover:123456@'192.168.0.106':3306 --discover-slaves-login=failover:123456 --force --daemon=start --candidates=failover:123456@'192.168.0.109':3306 --interval=5 -vvv --exec-after=/usr/local/sbin/test.sh

如果你是链式复制:M-->S1-->S2,则需要指定--slave从机,因为MySQLfailover本身只能检测到一主双从的架构,这里也不会影响到切换。

如果你是其他的复制:M-->S1-->S2/S3,这里也需要指定--slave参数,以便在故障转移时可以定位到新主机上。

如果你是以上两种复制方式,则也需要指定--candidates=参数,以便在故障转移时可以转移到指定的机器上。

其中有一个参数要说明一下:--exec-after

这个参数是在故障转移之后让MySQLfailover自动执行的脚本,必须要放在/usr/local/sbin/目录下才能生效。这里的主要作用就是配合proxysql中间件进行读写切换,通过设置read_only参数使proxysql中间件自己判断是写机还是读机。

这个参数有4个传入参数,分别是:

$1:旧master的IP

$2:旧master的端口

$3:新master的IP

$4:新master的端口

我的脚本:

#!/bin/bash
ip="192.168.0.112"    #因为我在命令行中指明了候选主机,那么这里就应该填写另一台slave了,要设置只读的slave机
port=3306
new_master_ip=$3    #接收到的第三个参数,下面有说明
new_master_port=$4    #接收到的第四个参数
mysql -ufailover -p123456 -h$new_master_ip -P$new_master_port -e "set global read_only=0;"    #这里设置新master为读写模式
mysql -ufailover -p123456 -h$ip -P$port -e "set global read_only=1;"    #设置slave为只读模式,和proxysql要配合使用进行读写分离。

这里说明:

由于proxysql读写分离的机制是检测服务器的read_only参数的,而且故障转移会自动将只读设置变成读写模式,所以脚本里要重新去另一台slave设置一下read_only参数才可以和proxysql相配合使用。

192.168.0.112就是另一台slave机。

三、启动服务,测试读写分离。

mysql -ufailover -p123456 -h127.0.0.1 -P6033    用程序账号连接。

mysql> use test
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
mysql> select * from test;
+------+
| id |
+------+
| 111 |
| 111 |
| 3 |
| 3 |
| 3 |
| 3 |
+------+
6 rows in set (0.00 sec)

mysql> insert into test values(3);
Query OK, 1 row affected (0.01 sec)

mysql> insert into test values(3);
Query OK, 1 row affected (0.00 sec)

mysql> insert into test values(3);
Query OK, 1 row affected (0.01 sec)

mysql> select * from test;
+------+
| id |
+------+
| 111 |
| 111 |
| 3 |
| 3 |
| 3 |
| 3 |
| 3 |
| 3 |
| 3 |
+------+
9 rows in set (0.00 sec)

mysql> \q

查看读写分离是否成功:mysql -uadmin -padmin -h 127.0.0.1 -P 6032

mysql> select * from stats_mysql_query_digest;
+-----------+--------------------+----------+--------------------+----------------------------------+------------+------------+------------+----------+----------+----------+
| hostgroup | schemaname | username | digest | digest_text | count_star | first_seen | last_seen | sum_time | min_time | max_time |
+-----------+--------------------+----------+--------------------+----------------------------------+------------+------------+------------+----------+----------+----------+
| 1 | test | failover | 0x6FA973F1E0331C0E | insert into test values(?) | 3 | 1536640645 | 1536640646 | 13013 | 1391 | 9671 |
| 2 | test | failover | 0x38DF1D37B3136F42 | select * from test | 2 | 1536640640 | 1536640649 | 1625 | 582 | 1043 |
| 1 | test | failover | 0x99531AEFF718C501 | show tables | 1 | 1536640630 | 1536640630 | 368 | 368 | 368 |
| 1 | test | failover | 0x02033E45904D3DF0 | show databases | 1 | 1536640630 | 1536640630 | 930 | 930 | 930 |
| 1 | information_schema | failover | 0x620B328FE9D6D71A | SELECT DATABASE() | 1 | 1536640630 | 1536640630 | 750 | 750 | 750 |
| 1 | information_schema | failover | 0x226CD90D52A2BA0B | select @@version_comment limit ? | 1 | 1536640627 | 1536640627 | 0 | 0 | 0 |
+-----------+--------------------+----------+--------------------+----------------------------------+------------+------------+------------+----------+----------+----------+
6 rows in set (0.01 sec)

观察hostgroup字段,可以看到insert语句发送到了写组上,select语句发送到了读组上。

现在来测试高可用:

KILL掉master的mysql进程:

[root@node1 ~]# ps -ef|grep mysql
root 17224 1 0 11:09 pts/0 00:00:00 /bin/sh /usr/local/mysql/bin/mysqld_safe --datadir=/usr/local/mysql/data --pid-file=/usr/local/mysql/data/mysql.pid
mysql 18126 17224 0 11:09 pts/0 00:00:05 /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --plugin-dir=/usr/local/mysql/lib/plugin --user=mysql --log-error=/usr/local/mysql/data/mysqld.log --open-files-limit=28192 --pid-file=/usr/local/mysql/data/mysql.pid --socket=/usr/local/mysql/mysql.sock --port=3306
root 18358 1509 0 13:24 pts/0 00:00:00 grep mysql
[root@node1 ~]# kill -9 17224
[root@node1 ~]# kill -9 18126
[root@node1 ~]# ps -ef|grep mysql
root 18360 1509 0 13:25 pts/0 00:00:00 grep mysql

MySQLfailover输出:

Q-quit R-refresh H-health G-GTID Lists U-UUIDs
Failed to reconnect to the master after 3 attemps.
Failover starting in 'auto' mode...
# Checking eligibility of slave 192.168.0.109:3306 for candidate.
# GTID_MODE=ON ... Ok
# Replication user exists ... Ok
# Candidate slave 192.168.0.109:3306 will become the new master.
# Checking slaves status (before failover).
# Preparing candidate for failover.
WARNING: IP lookup by name failed for 44,reason: Unknown host
WARNING: IP lookup by address failed for 192.168.0.109,reason: Unknown host
WARNING: IP lookup by address failed for 192.168.0.112,reason: Unknown host
# Missing transactions found on 192.168.0.112:3306. SELECT gtid_subset() = 0
# LOCK STRING: FLUSH TABLES WITH READ LOCK
# Read only is ON for 192.168.0.112:3306.
# Connecting candidate to 192.168.0.112:3306 as a temporary slave to retrieve unprocessed GTIDs.
# Change master command for 192.168.0.109:3306
# CHANGE MASTER TO MASTER_HOST = '192.168.0.112', MASTER_USER = 'backup', MASTER_PASSWORD = '123456', MASTER_PORT = 3306, MASTER_AUTO_POSITION=1
# Read only is OFF for 192.168.0.112:3306.
# UNLOCK STRING: UNLOCK TABLES
# Waiting for candidate to catch up to slave 192.168.0.112:3306.
# Slave 192.168.0.109:3306:
# QUERY = SELECT WAIT_UNTIL_SQL_THREAD_AFTER_GTIDS('c142ca67-b898-11e8-86e8-000c29367e64:1', 300)
# Return Code = 3
# Slave 192.168.0.109:3306:
# QUERY = SELECT WAIT_UNTIL_SQL_THREAD_AFTER_GTIDS('c777e02f-b898-11e8-86a0-000c29c6f346:1-4', 300)
# Return Code = 0
# Creating replication user if it does not exist.
# Stopping slaves.
# Performing STOP on all slaves.
WARNING: IP lookup by name failed for 44,reason: Unknown host
WARNING: IP lookup by address failed for 192.168.0.109,reason: Unknown host
WARNING: IP lookup by address failed for 192.168.0.112,reason: Unknown host
# Executing stop on slave 192.168.0.109:3306 WARN - slave is not configured with this master
# Executing stop on slave 192.168.0.109:3306 Ok
WARNING: IP lookup by address failed for 192.168.0.106,reason: Unknown host
# Executing stop on slave 192.168.0.112:3306 WARN - slave is not configured with this master
# Executing stop on slave 192.168.0.112:3306 Ok
WARNING: IP lookup by name failed for 44,reason: Unknown host
WARNING: IP lookup by address failed for 192.168.0.109,reason: Unknown host
# Switching slaves to new master.
# Change master command for 192.168.0.112:3306
# CHANGE MASTER TO MASTER_HOST = '192.168.0.109', MASTER_USER = 'backup', MASTER_PASSWORD = '123456', MASTER_PORT = 3306, MASTER_AUTO_POSITION=1
# Disconnecting new master as slave.
# Execute on 192.168.0.109:3306: RESET SLAVE ALL
# Starting slaves.
# Performing START on all slaves.
# Executing start on slave 192.168.0.112:3306 Ok
# Spawning external script.
# SCRIPT EXECUTED: /usr/local/sbin/test.sh 192.168.0.106 3306 192.168.0.109 3306      #这里可以看到在执行脚本了,传入了四个参数
# Script completed Ok.                                  #执行成功
# Checking slaves for errors.
# 192.168.0.112:3306 status: Ok
# Failover complete.
# Discovering slaves for master at 192.168.0.109:3306

Failover console will restart in 5 seconds.
# Attempting to contact 192.168.0.109 ... Success
# Attempting to contact 192.168.0.112 ... Success
MySQL Replication Failover Utility
Failover Mode = auto Next Interval = Sat Sep 15 18:11:45 2018

Master Information
------------------
Binary Log File Position Binlog_Do_DB Binlog_Ignore_DB
mysql-bin.000001 657

GTID Executed Set
b5c5054c-b898-11e8-8670-000c299e1daf:1 [...]

# Attempting to contact 192.168.0.109 ... Success
# Attempting to contact 192.168.0.112 ... Success
Replication Health Status
+----------------+-------+---------+--------+------------+---------+-------------+-------------------+-----------------+------------+-------------+--------------+------------------+---------------+-----------+----------------+------------+---------------+
| host | port | role | state | gtid_mode | health | version | master_log_file | master_log_pos | IO_Thread | SQL_Thread | Secs_Behind | Remaining_Delay | IO_Error_Num | IO_Error | SQL_Error_Num | SQL_Error | Trans_Behind |
+----------------+-------+---------+--------+------------+---------+-------------+-------------------+-----------------+------------+-------------+--------------+------------------+---------------+-----------+----------------+------------+---------------+
| 192.168.0.109 | 3306 | MASTER | UP | ON | OK | 5.7.22-log | mysql-bin.000001 | 657 | | | | | | | | | |
| 192.168.0.112 | 3306 | SLAVE | UP | ON | OK | 5.7.22-log | mysql-bin.000001 | 657 | Yes | Yes | 0 | No | 0 | | 0 | | 0 |
+----------------+-------+---------+--------+------------+---------+-------------+-------------------+-----------------+------------+-------------+--------------+------------------+---------------+-----------+----------------+------------+---------------+

已经成功转移到192.168.0.109上并提升为master。

查看proxysql是否成功转移:

mysql> select * from mysql_servers;
+--------------+----------------+------+--------+--------+-------------+-----------------+---------------------+---------+----------------+-------------+
| hostgroup_id | hostname | port | status | weight | compression | max_connections | max_replication_lag | use_ssl | max_latency_ms | comment |
+--------------+----------------+------+--------+--------+-------------+-----------------+---------------------+---------+----------------+-------------+
| 1 | 192.168.0.109 | 3306 | ONLINE | 1 | 0 | 1000 | 0 | 0 | 0 | Write Group |
| 2 | 192.168.0.112 | 3306 | ONLINE | 1 | 0 | 1000 | 0 | 0 | 0 | Read Group |
| 2 | 192.168.0.109 | 3306 | ONLINE | 1 | 0 | 1000 | 0 | 0 | 0 | Read Group |
+--------------+----------------+------+--------+--------+-------------+-----------------+---------------------+---------+----------------+-------------+
3 rows in set (0.00 sec)

可以看到旧master和旧slave的hostgroup_id 已经改变。来测试语句负载:

[root@nodetest ~]# mysql -ufailover -p123456 -h127.0.0.1 -P6033
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 9
Server version: 5.5.30 (ProxySQL)

Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> use test
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
mysql> select * from test;
+------+
| id |
+------+
| 111 |
| 111 |
| 3 |
| 3 |
| 3 |
| 3 |
| 3 |
| 3 |
| 3 |
| 4 |
| 45 |
| 695 |
| 6676 |
| 6676 |
+------+
14 rows in set (0.00 sec)

mysql> select @@hostname;
+------------+
| @@hostname |
+------------+
| node2 |
+------------+
1 row in set (0.01 sec)

mysql> insert into test values(43536);
Query OK, 1 row affected (0.01 sec)

mysql> select * from test;
+-------+
| id |
+-------+
| 111 |
| 111 |
| 3 |
| 3 |
| 3 |
| 3 |
| 3 |
| 3 |
| 3 |
| 4 |
| 45 |
| 695 |
| 6676 |
| 6676 |
| 43536 |
+-------+
15 rows in set (0.00 sec)

mysql> \q
Bye

查看proxysql:

[root@nodetest ~]# mysql -uadmin -padmin -h127.0.0.1 -P6032
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 10
Server version: 5.5.30 (ProxySQL Admin Module)

Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> select * from stats_mysql_query_digest_reset;
+-----------+--------------------+----------+--------------------+----------------------------------+------------+------------+------------+----------+----------+----------+
| hostgroup | schemaname | username | digest | digest_text | count_star | first_seen | last_seen | sum_time | min_time | max_time |
+-----------+--------------------+----------+--------------------+----------------------------------+------------+------------+------------+----------+----------+----------+
| 1 | test | failover | 0x6FA973F1E0331C0E | insert into test values(?) | 1 | 1536649818 | 1536649818 | 11699 | 11699 | 11699 |
| 2 | test | failover | 0x82A12D4C4E7B0A28 | select @@hostname | 1 | 1536649811 | 1536649811 | 495 | 495 | 495 |
| 2 | test | failover | 0x38DF1D37B3136F42 | select * from test | 2 | 1536649806 | 1536649820 | 1253 | 547 | 706 |
| 1 | test | failover | 0x02033E45904D3DF0 | show databases | 1 | 1536649802 | 1536649802 | 674 | 674 | 674 |
| 2 | information_schema | failover | 0x620B328FE9D6D71A | SELECT DATABASE() | 1 | 1536649802 | 1536649802 | 880 | 880 | 880 |
| 1 | test | failover | 0x99531AEFF718C501 | show tables | 1 | 1536649802 | 1536649802 | 590 | 590 | 590 |
| 1 | information_schema | failover | 0x226CD90D52A2BA0B | select @@version_comment limit ? | 1 | 1536649800 | 1536649800 | 0 | 0 | 0 |
+-----------+--------------------+----------+--------------------+----------------------------------+------------+------------+------------+----------+----------+----------+
7 rows in set (0.00 sec)

现在的读写组都是旧slave机,所以可以看到插入和查询语句都已经负载到了192.168.0.109这台机器上,证明高可用成功。

注意:

You should also note that, in MySQL 5.6.7 and later, enforcing foreign key relationships between tables in different databases causes multithreaded slaves to use sequential rather than parallel mode, which can have a negative impact on performance. (Bug #14092635)

意思是说如果不同库之间开启外键的话,会对并行复制的性能有很大影响,因此,在任何情况下,都不要使用外键。

未经允许,谢绝转载

mysqlfailover高可用与proxysql读写分离配置的更多相关文章

  1. Proxysql读写分离配置

    ProxySQL是Percona主推的读写分离中间件,下载地址为: https://www.percona.com/downloads/proxysql/ 一.安装 1:下载 wget https:/ ...

  2. MHA+ProxySQL 读写分离高可用

    文档结构如下: 1.ProxySQL说明 ProxySQL是mysql的一款中间件的产品,是灵活的mysql代理层,可以实现读写分离,支持query路由器的功能,支持动态指定sql进行缓存,支持动态加 ...

  3. MySQL ProxySQL读写分离实践

    目的 在上一篇文章MySQL ProxySQL读写分离使用初探里初步介绍了ProxySQL的使用,本文继续介绍它的一些特点和DBProxy的性能差异.深入一些去了解ProxySQL,通过测试来说明Pr ...

  4. Mycat入门配置_读写分离配置

    1.Mycat的分片 两台数据库服务器: 192.168.80.11 192.168.80.4 操作系统版本环境:centos6.5 数据库版本:5.6 mycat版本:1.4 release 数据库 ...

  5. MySQL主从同步、读写分离配置步骤、问题解决笔记

    MySQL主从同步.读写分离配置步骤.问题解决笔记 根据要求配置MySQL主从备份.读写分离,结合网上的文档,对搭建的步骤和出现的问题以及解决的过程做了如下笔记:       现在使用的两台服务器已经 ...

  6. MySQL5.6 Replication主从复制(读写分离) 配置完整版

    MySQL5.6 Replication主从复制(读写分离) 配置完整版 MySQL5.6主从复制(读写分离)教程 1.MySQL5.6开始主从复制有两种方式: 基于日志(binlog): 基于GTI ...

  7. Mysql一主多从和读写分离配置简记

    近期开发的系统中使用MySQL作为数据库,由于数据涉及到Money,所以不得不慎重.同时,用户对最大访问量也提出了要求.为了避免Mysql成为性能瓶颈并具备很好的容错能力,特此实现主从热备和读写分离. ...

  8. yii2的数据库读写分离配置

    简介 数据库读写分离是在网站遇到性能瓶颈的时候最先考虑优化的步骤,那么yii2是如何做数据库读写分离的呢?本节教程来给大家普及一下yii2的数据库读写分离配置. 两个服务器的数据同步是读写分离的前提条 ...

  9. Redis高可用之哨兵模式Sentinel配置与启动(五)

    0.Redis目录结构 1)Redis介绍及部署在CentOS7上(一) 2)Redis指令与数据结构(二) 3)Redis客户端连接以及持久化数据(三) 4)Redis高可用之主从复制实践(四) 5 ...

随机推荐

  1. 一个小时学会 MySQL 数据库

    随着移动互联网的结束与人工智能的到来大数据变成越来越重要,下一个成功者应该是拥有海量数据的,数据与数据库你应该知道. 一.数据库概要 数据库(Database)是存储与管理数据的软件系统,就像一个存入 ...

  2. java基础第十一篇之Date、Math、自动装箱和拆箱

    Date类 表示一个瞬间,就是一个时刻 * * 构造方法: * public Date();//创建一个表示当前系统时间的Date对象 * public Date(long time);//毫秒值,距 ...

  3. 利用system.reflection遍历一个类的变量成员

    假设有下面一个类,在程序中已初始化,如何获取里面的变量成员name,age,onduty及其值呢? public class Employee { public string name; public ...

  4. vue中params & query的比较

    共同点: 1.都可以传值 2.在另外一个组件中传递值的时候,都是放在$route中 不同点: 1.传值时候,url的表现不一样 query /orderInfo?xxx=yyy&aaa=bbb ...

  5. Unity 关于时间

    一.引言 本篇博客 包括:unity中帧的耗时,时间缩放比例,常用日期时间的获取和计算,测试一段程序的耗时. 二.帧时间 名称 描述 Time.time (只读)表示从游戏开发到现在的时间,会随着游戏 ...

  6. [Android基础]Android四大组件之BroadCast

    BroadCast的定义: 广播是一种订阅--通知 事件,广播接收者向Android系统 register (订阅广播),广播发送者向Adnroid系统 sendBroadCast(发送广播),然后A ...

  7. 《深入理解java虚拟机》笔记(5)垃圾回收算法及垃圾收集器

    一.标记-清除算法 算法:分为标记和清除两个阶段,首先标记出所有需要回收的对象,再对标记对象进行回收. 不足之处:效率不高,会产生大量不连续内存碎片,导致下次分配较大内存时,若内存不足不得不触发垃圾回 ...

  8. 微信支付(java版本)_支付结果通知

    应用场景: 支付完成后,微信会把相关支付结果和用户信息发送给商户,商户需要接收处理,并返回应答. 对后台通知交互时,如果微信收到商户的应答不是成功或超时,微信认为通知失败,微信会通过一定的策略定期重新 ...

  9. c#基础值类和引用类型

    //值类型:int double char decimal bool enum struct //引用类型:string 数组 自定义类 集合 object 接口 值传递传递的值得本身 引用传递传递的 ...

  10. 初学Android,创建,启动,停止Service(五十八)

    Service跟Windows系统里的服务概念差不多,都在后台执行,它跟Activity的最大区别就是,它是无界面的 开发Service与开发Activity的步骤类似 1.定义一个继承Service ...