死锁

  1. for update 是否锁表

  2. 事务传播 @Transactional

  3. 异常 MySQLTransactionRollbackException

  4. 隔离级别

    1
    2
    3
    4
    5
    6
    7
    8
    show engines;
    show variables like '%storage_engine%';
    select version();
    select @@tx_isolation; -- 查看数据库隔离级别
    select @@autocommit;
    show variables like 'innodb_lock_wait_timeout';
    show global variables like 'innodb_lock_wait_timeout';
    set innodb_lock_wait_timeout=1000; -- 设置当前会话 Innodb 行锁等待超时时间,单位秒
  5. INNODB 事务

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    SELECT
    `trx_id`,
    `trx_state` AS 事务状态,
    `trx_started` AS 开始时间,
    `trx_requested_lock_id`,
    `trx_wait_started`,
    `trx_weight` AS 权重,
    `trx_mysql_thread_id` AS 线程ID,
    `trx_query`,
    `trx_operation_state`,
    `trx_tables_locked` AS 锁表个数,
    `trx_rows_locked` AS 锁表行数,
    `trx_rows_modified` AS 修改行数,
    `trx_autocommit_non_locking` AS 是否自动提交
    FROM
    INNODB_TRX t;
  6. 场景模拟

spring-boot-2.0

context-path

1
2
3
4
# 旧版
server.context-path: xxxx
# 新版
server.servlet.context-path: xxxx

Actuator

Dependency

1
2
3
4
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>

Endpoints

执行器端点(endpoints)可用于监控应用及与应用进行交互

  • env 显示来自Spring的 ConfigurableEnvironment的属性
  • health 显示应用的健康信息
  • info 显示任意的应用信息
  • metrics 展示当前应用的metrics信息
  • mappings 显示一个所有@RequestMapping路径的集合列表
  • logfile 返回日志文件内容(如果设置了logging.file或logging.path属性的话)
  • prometheus 以可以被Prometheus服务器抓取的格式显示metrics信息

启用禁用:

1
2
management.endpoint.metrics.enabled=true
management.endpoint.env.enabled=true

sonar

start

1
2
3
4
5
6
7
8
9
docker run -d --name sonarqube \
-p 9797:9000 -p 9092:9092 \
-v /opt/sonarqube/temp:/opt/sonarqube/temp \
-v /opt/sonarqube/conf:/opt/sonarqube/conf \
-v /opt/sonarqube/extensions:/opt/sonarqube/extensions \
-e SONARQUBE_JDBC_USERNAME=username \
-e SONARQUBE_JDBC_PASSWORD=password \
-e SONARQUBE_JDBC_URL="jdbc:mysql://192.168.20.234:3306/sonar?useUnicode=true&characterEncoding=utf8" \
sonarqube:7.1

postgres db

1
2
3
4
5
6
7
8
9
docker pull postgres:10
docker pull sonarqube:7.9.1-community
docker run -d -p 5432:5432 -e POSTGRES_PASSWORD=1 --name postgres postgres:10
docker run -d --name sonarqube \
-p 9000:9000 \
-e "SONARQUBE_JDBC_URL=jdbc:postgresql://192.168.114.131:5432/sonar" \
-e "SONARQUBE_JDBC_USERNAME=postgres" \
-e "SONARQUBE_JDBC_PASSWORD=1" \
sonarqube:7.9.1-community

plugins

1
2
3
4
5
6
7
8
FROM sonarqube
ADD ./sonar-l10n-zh-plugin-1.15.jar /opt/sonarqube/extensions/plugins/sonar-l10n-zh-plugin-1.15.jar
ADD ./sonar-java-plugin-4.7.0.9212.jar /opt/sonarqube/extensions/plugins/sonar-java-plugin-4.7.0.9212.jar
ADD ./sonar-findbugs-plugin-3.4.4.jar /opt/sonarqube/extensions/plugins/sonar-findbugs-plugin-3.4.4.jar
ADD ./checkstyle-sonar-plugin-3.6.jar /opt/sonarqube/extensions/plugins/checkstyle-sonar-plugin-3.6.jar
ADD ./backelite-sonar-swift-plugin-0.3.2.jar /opt/sonarqube/extensions/plugins/backelite-sonar-swift-plugin-0.3.2.jar
ADD ./sonar-web-plugin-2.5.0.476.jar /opt/sonarqube/extensions/plugins/sonar-web-plugin-2.5.0.476.jar
ADD ./sonar-javascript-plugin-2.21.0.4409.jar /opt/sonarqube/extensions/plugins/sonar-javascript-plugin-2.21.0.4409.jar

IDE Support

Eclipse
IDEA

maven项目sonar扫描本地配置和扫描相关命令

1
mvn sonar:sonar

spring-cloud-config

dependency

动态刷新

使用限制

@RefreshScope @Configuration 不能同时在一个类上使用
原因说明:

@RefreshScope works (technically) on an @Configuration class, but it might lead to surprising behaviour: e.g. it does not mean that all the @Beans defined in that class are themselves @RefreshScope. Specifically, anything that depends on those beans cannot rely on them being updated when a refresh is initiated, unless it is itself in @RefreshScope (in which it will be rebuilt on a refresh and its dependencies re-injected, at which point they will be re-initialized from the refreshed @Configuration).

参考:
https://stackoverflow.com/questions/45137555/refreshscope-not-working-spring-boot
http://projects.spring.io/spring-cloud/spring-cloud.html#_refresh_scope

druid数据库连接池通用配置

dependency

1
2
3
4
5
6
<!-- https://mvnrepository.com/artifact/com.alibaba/druid -->
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid</artifactId>
<version>1.1.10</version>
</dependency>

config

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
<bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource" init-method="init" destroy-method="close">
<!-- 基本属性 url、user、password -->
<property name="url" value="${jdbc_url}" />
<property name="username" value="${jdbc_user}" />
<property name="password" value="${jdbc_password}" />

<!-- 配置初始化大小、最小、最大 -->
<property name="maxActive" value="20" />
<property name="initialSize" value="1" />
<!-- 配置获取连接等待超时的时间 -->
<property name="maxWait" value="60000" />
<property name="minIdle" value="1" />

<!-- 配置间隔多久才进行一次检测,检测需要关闭的空闲连接,单位是毫秒 -->
<property name="timeBetweenEvictionRunsMillis" value="60000" />
<!-- 配置一个连接在池中最小生存的时间,单位是毫秒 -->
<property name="minEvictableIdleTimeMillis" value="300000" />

<!-- 用来检测连接是否有效的sql,要求是一个查询语句,常用select 'x'。如果validationQuery为null,testOnBorrow、testOnReturn、testWhileIdle都不会起作用。 -->
<property name="validationQuery" value="SELECT 1" />
<property name="testWhileIdle" value="true" />
<property name="testOnBorrow" value="false" />
<property name="testOnReturn" value="false" />

<!-- 打开PSCache,并且指定每个连接上PSCache的大小 -->
<property name="poolPreparedStatements" value="true" />
<property name="maxPoolPreparedStatementPerConnectionSize" value="20" />

<!-- 配置监控统计拦截的filters -->
<property name="filters" value="stat" />

<!-- 1.1.4中新增配置,如果有initialSize数量较多时,打开会加快应用启动时间 -->
<property name="asyncInit" value="true" />
</bean>

error: Error creating bean with name ‘dataSource’

Druid连接池与spring cloud config搭配使用时出现异常
错误堆栈信息:

1
2
3
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource': Could not bind properties to DruidDataSourceWrapper (prefix=spring.datasource, ignoreInvalidFields=false, ignoreUnknownFields=true, ignoreNestedProperties=false); nested exception is org.springframework.validation.BindException: org.springframework.boot.bind.RelaxedDataBinder$RelaxedBeanPropertyBindingResult: 3 errors
Field error in object 'spring.datasource' on field 'driverClassName': rejected value [com.mysql.jdbc.Driver]; codes [methodInvocation.spring.datasource.driverClassName,methodInvocation.driverClassName,methodInvocation.java.lang.String,methodInvocation]; arguments [org.springframework.context.support.DefaultMessageSourceResolvable: codes [spring.datasource.driverClassName,driverClassName]; arguments []; default message [driverClassName]]; default message [Property 'driverClassName' threw exception; nested exception is java.lang.UnsupportedOperationException]
Field error in object 'spring.datasource' on field 'url'

异常出现代码位置:

1
2
3
4
5
6
7
8
9
10
11
public void setDriverClassName(String driverClass) {
if (inited) {
if (StringUtils.equals(this.driverClass, driverClass)) {
return;
}

throw new UnsupportedOperationException();
}

this.driverClass = driverClass;
}

代码中如有@PostConstruct并在其中进行了对数据库查询更新等于数据源有关的操作,则会出现此错误

lombok

dependency

1
2
3
4
5
6
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.16.18</version>
<scope>provided</scope>
</dependency>

IDE支持

Eclipse
IDEA

@Data

@Getter

@Setter

@Slf4j

@AllArgsConstructor

@EqualsAndHashCode

mybatis

batch update

批量更新
eg:

1
2
3
4
5
6
update table_post p
inner join (
SELECT u.user_id,u.post_count
FROM table_user u
) as c_u on p.user_id = c_u.user_id
set u.post_count=c_u.post_count;

mapper中batch update写法:

1
2
3
4
5
6
7
8
9
<update id="batchUpdate"  parameterType="java.util.List">
<foreach collection="list" item="item" index="index" open="" close="" separator=";">
update test
<set>
test=${item.test}+1
</set>
where id = ${item.id}
</foreach>
</update>

TIP:数据库连接必须配置:&allowMultiQueries=true

文档

中文文档
http://www.mybatis.org/mybatis-3/zh/

mybatis-spring
http://www.mybatis.org/spring/zh/

MyBatis Generator
http://www.mybatis.org/generator/
http://generator.sturgeon.mopaas.com/

vpn

注册

连接vpn后在管理员模式命令行执行以下命令进行注册

1
2
3
REG ADD HKLM\SYSTEM\CurrentControlSet\Services\PolicyAgent /v AssumeUDPEncapsulationContextOnSendRule /t REG_DWORD /d 0x2 /f
REG ADD HKLM\SYSTEM\CurrentControlSet\Services\RasMan\Parameters /v ProhibitIpSec /t REG_DWORD /d 0x0 /f
REG ADD HKLM\SYSTEM\CurrentControlSet\Services\PolicyAgent /v AllowL2TPWeakCrypto /t REG_DWORD /d 0x1 /f

fiddler

urlreplace

路由拦截重定向
eg:

1
2
urlreplace 192.168.20.220/hub 192.168.21.110:8080/hub
urlreplace test.api.com localhost:8088

手机抓包

参考:https://www.cnblogs.com/yyhh/p/5140852.html

android

版本 9

IDE
Android Studio

val
val a: Int = ch.toInt();

var 变量
val 常量
常量不能再次更改

boolean

arrayOf

Array

日志

swith ==> when

for 倒序遍历

Your browser is out-of-date!

Update your browser to view this website correctly. Update my browser now

×