mvn 坑

mvn 构建时pom继承父pom时, plugin的覆盖有坑

1
2
3
4
5
6
7
8
9
10
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<excludes>
<exclude></exclude>
</excludes>
</configuration>
</plugin>

在子pom里面为plugin定义 属性, 如果没有增加 属性, 会继承父pom的

java-debug-remote.md

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17

export TOMCAT_USER="tomcat"
export JAVA_OPTS="-Xms2048m -Xmx2048m -XX:NewSize=256m -XX:PermSize=256m -server -XX:+DisableExplicitGC -verbose:gc -XX:+PrintGCDateStamps -XX:+PrintGCDetails -Xloggc:$CATALINA_BASE/logs/gc.log
-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=127.0.0.1:60004"
chown -R tomcat:tomcat $CATALINA_BASE/logs
chown -R tomcat:tomcat $CATALINA_BASE/cache
chown -R tomcat:tomcat $CATALINA_BASE/conf
chown -R tomcat:tomcat $CATALINA_BASE/work
chown -R tomcat:tomcat $CATALINA_BASE/temp

export JAVA_OPTS=${JAVA_OPTS}"
-Dcom.sun.management.jmxremote
-Dcom.sun.management.jmxremote.port=60005
-Dcom.sun.management.jmxremote.host=193.168.2.187
-Dcom.sun.management.jmxremote.local.only=true
-Dcom.sun.management.jmxremote.authenticate=false
-Dcom.sun.management.jmxremote.ssl=false
1
sudo socat TCP4-LISTEN:50056,fork,range=100.80.180.190/32 TCP4:127.0.0.1:60004

java-framework-es

为es 建立索引的时候es存的是时间戳, 如果在字段上加上 Jsonformat的注解会序列化成jsonformat的值, 和时间戳的类型冲突了, 这样就就会报错

java状态机使用思考

transferbiz

事件入口, 业务调用可从该入口进入, 如果有需要保证一致性的逻辑, 可增加回调

transferbiz应该只被transferbiz以及外部业务接口调用

handler

处理状态变更的代码, 一般而言只用来处理状态变更导致的核心实体数据变化, 仅仅跟状态相关

严格意义上, 只处理本状态机自身状态变更相关的逻辑, 如果有外部变更, 请放在transferbiz里面

简单的测试小工具

test.html

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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<script src="https://ajax.aspnetcdn.com/ajax/jQuery/jquery-3.2.1.min.js"></script>
<body>

<!--<a href="https://www.baidu.com" download="baidu.html">下载</a>-->
<button onclick="run()">测试接口</button>
<button onclick="runConcurrency()">并发测试接口</button>
</body>

<script>

var settings = {
"async": true,
"crossDomain": true,
"url": "http://local.ims.qunarman.com:8080/pay/freeRoom/deduction.json",
"method": "POST",
"headers": {
"content-type": "application/json",
"cache-control": "no-cache",
"postman-token": "cf69a168-df11-df81-c8cf-61dac0168c72"
},
"processData": false,
"data": "{\n \"hotelSeq\": \"sanya_2048\",\n \"freeRoomPayParam\": {\n \"freeRooms\": [\n {\n \"saleSRoomId\": 100000,\n \"freeRoomTypeName\": \"标间\",\n \"forbiddenDateRangeList\": [\n {\n \"startTime\": \"2017-12-25\",\n \"endTime\": \"2017-12-29\"\n }\n ],\n \"roomQuantity\": 1,\n \"weekendSale\": true\n }\n ]\n },\n \"order\": \"o611392963963\",\n \"orderVersion\": 1,\n \"code\": \"1234\"\n}"
}

function run() {
console.log("开始请求");
$.ajax(settings).done(function (response) {
console.log(response);
});
}

function runConcurrency() {
for (var i = 0; i < 1000; i++) {
console.log("开始请求第", i + 1, "次");
$.ajax(settings).done(function (response) {
console.log(response);
});
}

}

</script>
</html>

java_base_exception_thought

关于java 异常的捕获

基本原则: 有能力处理的时候就处理; 没有能力处理, 或者不知道怎么处理, 就抛出

比方说发短信需要重试, 一次失败可以把异常捕获住, 打印warn日志. 然后重试, 直到达到指定次数仍然失败就抛出异常

这里的有能力处理是: 打印日志重发; 没有能力处理是重试达到指定次数抛出异常

一般场景下, 异常都是直接抛出, 包括http, task, 都是抛出给最外层处理

异常的种类

ignoreExcetpion: 业务无法向下进行, 或者进入了不正常的阶段, 需要抛出业务异常

FatalException: 致命的业务错误产生了, 需要触发告警了, 需要抛出非业务异常. 比如参数不合法, 脏数据.

异常的监控

异常一般意味着问题或者风险. 需要做对应的监控. 宏观地说: 关键业务的失败, 成功, 都要加监控.