forever杨的个人博客

I want to be forever young!


  • 首页

  • 文章202

  • 分类31

  • 标签175

  • 公益

  • 关于

  • 搜索

查询系统信息

发表于 2024-02-27 | 分类于 Linux
| 字数: 388 | 时长 ≈ 1 分钟
标签 Java

[root@zhtest1 ~]# cat /etc/issue
\S
Kernel \r on an \m

[root@zhtest1 ~]# lsb_release -a
-bash: lsb_release: command not found
[root@zhtest1 ~]# cat /proc/version
Linux version 4.19.12-1.el7.elrepo.x86_64 (mockbuild@Build64R7) (gcc version 4.8.5 20150623 (Red Hat 4.8.5-36) (GCC)) #1 SMP Fri Dec 21 11:06:36 EST 2018
[root@zhtest1 ~]# cat /etc/redhat-release
CentOS Linux release 7.9.2009 (Core)

route 路由配置

发表于 2023-08-22 | 更新于 2024-01-12 | 分类于 Linux
| 字数: 716 | 时长 ≈ 1 分钟
标签 shell route

查看路由

1
2
3
4
5
6
7
8
9
[root@yl ~]$ route
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
default gateway 0.0.0.0 UG 0 0 0 eth0
default gateway 0.0.0.0 UG 100 0 0 eth0
10.254.39.0 0.0.0.0 255.255.255.0 U 0 0 0 eth0
10.254.39.0 0.0.0.0 255.255.255.0 U 100 0 0 eth0
link-local 0.0.0.0 255.255.0.0 U 0 0 0 eth0
172.19.0.0 0.0.0.0 255.255.0.0 U 0 0 0 br-078ffef7667a

配置路由

1
2
3
4
# 添加一条网络路由
route add -net 172.23.3.0/24 gw 10.254.2.254
# 删除一条网络路由
route del -net 172.23.3.0/24 gw 10.254.2.254

JAVA 通用树形结构数据构建工具类

发表于 2022-11-22 | 更新于 2024-01-12 | 分类于 Java
| 字数: 5.4k | 时长 ≈ 5 分钟
标签 Tree

TreeNode

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
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

/**
* 树结构
*/
@Data
@NoArgsConstructor
public class TreeNode implements Serializable {
private static final long serialVersionUID = -1506101868495287822L;

@ApiModelProperty(value = "节点Id")
private String id;

@ApiModelProperty(value = "节点名")
private String label;

@ApiModelProperty(value = "父节点Id")
private String parentId;

@ApiModelProperty(value = "子节点列表")
private List<TreeNode> children = new ArrayList<>();
}
阅读全文 »

Java Validation 使用

发表于 2022-09-24 | 更新于 2024-01-12 | 分类于 Java
| 字数: 447 | 时长 ≈ 1 分钟
标签 hibernate-validation javax-validation
  • NotBlank

    基础类型是用来判断是否为空

    1
    2
    @NotBlank(message = "员工工号不能为空")
    private String empNo;
  • NotNull

    1
    2
    @NotNull(message = "员工 id 不能为空")
    private Long empId;
  • Pattern

    1
    2
    @Pattern(regexp = "^G0[a-zA-Z0-9]+$", message = "员工工号不符合要求,请以 G0 开头,其余均需为数字或字母组合")
    private String empNo;
  • Length

    1
    2
    3
    @Length(max = 25, message = "员工工号长度不能超过{max}个字符")
    // @Length(max = 45, message = "员工工号[${validatedValue}]长度不能超过{max}个字符")
    private String empNo;
  • sdf

mysql 异常处理

发表于 2022-09-16 | 更新于 2024-01-12 | 分类于 mysql
| 字数: 846 | 时长 ≈ 1 分钟
标签 mysql

flush-hosts 异常

错误原因

​ 同一个ip在短时间内产生太多(超过mysql数据库max_connection_errors的最大值)中断的数据库连接而导致的阻塞。
​ 当客户端连接服务端超时(超过connect_timeout),服务端就会给这个客户端记录一次error,当出错的次数达到max_connect_errors的时候,这个客户端就会被锁定,从而应用出现异常:
java.sql.SQLException: null, message from server: "Host 'xxx' is blocked because of many connection errors; unblock with 'mysqladmin flush-hosts'"。

参考:https://www.cnblogs.com/kerrycode/p/8405862.html

解决办法

  • 方法一

    进入数据库将max_connection_errors参数调高,也可以在my.cnf文件中修改不过需要重启MySQL。

    查看该属性设置为多大

    1
    show global variables like '%max_connect_errors%';

    根据业务尽量把这个值设置大一点,MySQL max_connect_errors默认值为100,我们可以根据具体需要设置大一点,这里设置为500。

    1
    set global max_connect_errors=500;

注意:数据库主从或集群模式时,有节点都需要单独设置。

  • 方法二

    1
    2
    3
    mysqladmin -uroot -proot -h192.168.1.1 flush-hosts
    或
    flush hosts;

    注意:数据库主从或集群模式时,要确定是被哪个MySQL服务拒绝了,刷新对应的服务器即可,不确定的话可以所有节点都刷新。

POI 操作 Excel 工具

发表于 2022-08-20 | 更新于 2024-01-12 | 分类于 Java
| 字数: 7.5k | 时长 ≈ 7 分钟
标签 POI Excel

poi 3.8 及以上版本使用 SXSSFWorkbook 性能会更高点,内存占用会更少

  • HSSF:是操作 Excel97-2003 版本,扩展名为.xls。
  • XSSF:是操作 Excel2007 版本开始,扩展名为.xlsx。
  • SXSSF:是在 XSSF 基础上,POI3.8 版本开始提供的一种支持低内存占用的操作方式,扩展名为.xlsx。
  • SXSSFWorkbook 需要指定的字体库支持。
阅读全文 »

spring boot + redis序列化方式

发表于 2022-07-24 | 更新于 2024-01-12 | 分类于 Java
| 字数: 6.8k | 时长 ≈ 6 分钟
标签 redis spring-boot

Kryo

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
import org.springframework.data.redis.serializer.RedisSerializer;
import org.springframework.data.redis.serializer.SerializationException;

import com.esotericsoftware.kryo.Kryo;
import com.esotericsoftware.kryo.io.Input;
import com.esotericsoftware.kryo.io.Output;

/**
* kryo 序列化
*/
public class KryoSerializer<T> implements RedisSerializer<T> {

private static final int BUFFER_SIZE = 2048;
private static final byte[] EMPTY_BYTE_ARRAY = new byte[0];
private static final ThreadLocal<Kryo> KRYOS = ThreadLocal.withInitial(Kryo::new);

@Override
public byte[] serialize(T t) throws SerializationException {
if (null == t) {
return EMPTY_BYTE_ARRAY;
}
// -1 代表无限制,实际中依业务修改
Output output = new Output(BUFFER_SIZE, -1);
Kryo kryo = KRYOS.get();
kryo.writeClassAndObject(output, t);
output.flush();
return output.toBytes();
}

@Override
public T deserialize(byte[] bytes) throws SerializationException {
if (null == bytes || bytes.length <= 0) {
return null;
}
Input input = new Input(bytes);
Kryo kryo = KRYOS.get();
T t = (T) kryo.readClassAndObject(input);
input.close();
return t;
}
}

LZ4

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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;

import org.apache.commons.io.IOUtils;
import org.springframework.data.redis.serializer.RedisSerializer;
import org.springframework.data.redis.serializer.SerializationException;

import net.jpountz.lz4.LZ4BlockInputStream;
import net.jpountz.lz4.LZ4BlockOutputStream;
import net.jpountz.lz4.LZ4Compressor;
import net.jpountz.lz4.LZ4Factory;
import net.jpountz.lz4.LZ4FastDecompressor;

/**
* LZ4 压缩
*/
public class LZ4Serializer implements RedisSerializer<Object> {

private static final int BUFFER_SIZE = 4096;

private RedisSerializer<Object> innerSerializer;
private LZ4FastDecompressor decompresser;
private LZ4Compressor compressor;

public LZ4Serializer(RedisSerializer<Object> innerSerializer) {
this.innerSerializer = innerSerializer;
LZ4Factory factory = LZ4Factory.fastestInstance();
this.compressor = factory.fastCompressor();
this.decompresser = factory.fastDecompressor();
}

@Override
public byte[] serialize(Object graph) throws SerializationException {
if (graph == null) {
return new byte[0];
}
ByteArrayOutputStream byteOutput = null;
LZ4BlockOutputStream compressedOutput = null;
try {
byte[] bytes = innerSerializer.serialize(graph);
byteOutput = new ByteArrayOutputStream();
compressedOutput = new LZ4BlockOutputStream(byteOutput, BUFFER_SIZE, compressor);
compressedOutput.write(bytes);
compressedOutput.finish();
byte[] compressBytes = byteOutput.toByteArray();
return compressBytes;
} catch (Exception e) {
throw new SerializationException("LZ4 Serialization Error", e);
} finally {
IOUtils.closeQuietly(compressedOutput);
IOUtils.closeQuietly(byteOutput);
}
}

@Override
public Object deserialize(byte[] bytes) throws SerializationException {

if (bytes == null || bytes.length == 0) {
return null;
}

ByteArrayOutputStream baos = null;
LZ4BlockInputStream lzis = null;
try {
baos = new ByteArrayOutputStream(BUFFER_SIZE);
lzis = new LZ4BlockInputStream(new ByteArrayInputStream(bytes), decompresser);
int count;
byte[] buffer = new byte[BUFFER_SIZE];
while ((count = lzis.read(buffer)) != -1) {
baos.write(buffer, 0, count);
}
Object result = innerSerializer.deserialize(baos.toByteArray());
return result;
} catch (Exception e) {
throw new SerializationException("LZ4 deserizelie error", e);
} finally {
IOUtils.closeQuietly(lzis);
IOUtils.closeQuietly(baos);
}
}
}

GZip

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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
public class GzipSerializer implements RedisSerializer<Object> {

public static final int BUFFER_SIZE = 4096;
private RedisSerializer<Object> innerSerializer;

public GzipSerializer(RedisSerializer<Object> innerSerializer) {
this.innerSerializer = innerSerializer;
}

@Override
public byte[] serialize(Object graph) throws SerializationException {
if (graph == null) {
return new byte[0];
}
ByteArrayOutputStream bos = null;
GZIPOutputStream gzip = null;
try {
// 序列化
byte[] bytes = innerSerializer.serialize(graph);
bos = new ByteArrayOutputStream();
gzip = new GZIPOutputStream(bos);
// 压缩
gzip.write(bytes);
gzip.finish();
byte[] result = bos.toByteArray();
return result;
} catch (Exception e) {
throw new SerializationException("Gzip Serialization Error", e);
} finally {
IOUtils.closeQuietly(bos);
IOUtils.closeQuietly(gzip);
}
}

@Override
public Object deserialize(byte[] bytes) throws SerializationException {

if (bytes == null || bytes.length == 0) {
return null;
}

ByteArrayOutputStream bos = null;
ByteArrayInputStream bis = null;
GZIPInputStream gzip = null;
try {
bos = new ByteArrayOutputStream();
bis = new ByteArrayInputStream(bytes);
gzip = new GZIPInputStream(bis);
byte[] buff = new byte[BUFFER_SIZE];
int n;
// 解压
while ((n = gzip.read(buff, 0, BUFFER_SIZE)) > 0) {
bos.write(buff, 0, n);
}
// 反序列化
Object result = innerSerializer.deserialize(bos.toByteArray());
return result;
} catch (Exception e) {
throw new SerializationException("Gzip deserizelie error", e);
} finally {
IOUtils.closeQuietly(bos);
IOUtils.closeQuietly(bis);
IOUtils.closeQuietly(gzip);

}
}
}

FST

略

fastjson

略

SSL 的发展历史

发表于 2022-07-24 | 更新于 2024-01-12 | 分类于 Java
| 字数: 1.1k | 时长 ≈ 1 分钟
标签 SSL TSL

​ 想在网络世界中,让用户无感知地实现安全通讯,最合理的做法就是在传输层之上、应用层之下加入专门的安全层来实现。这样对于上层原本是基于 HTTP 的 Web 应用来说,甚至都察觉不到有什么影响。构建传输安全层这个想法,甚至可以说是和万维网的历史一样长,早在 1994 年,就已经有公司开始着手去实践了:

阅读全文 »

Linux nc 命令

发表于 2022-06-26 | 更新于 2024-01-12 | 分类于 Linux
| 字数: 24 | 时长 ≈ 1 分钟
标签 shell nc

nc

监听端口的网络

1
$ nc -l 8882

iTerm 使用

发表于 2022-06-05 | 更新于 2024-01-12 | 分类于 MacOS
| 字数: 123 | 时长 ≈ 1 分钟
标签 iTerm

问题 一:使用 iTerm 免输入密码登录问题。

阅读全文 »

Jwt 工具类

发表于 2022-05-21 | 更新于 2022-06-21 | 分类于 Java
| 字数: 39k | 时长 ≈ 35 分钟
标签 jwt

依赖包

1
2
3
4
5
6
7
8
9
10
<dependency>
<groupId>com.nimbusds</groupId>
<artifactId>nimbus-jose-jwt</artifactId>
<version>9.4.1</version>
</dependency>
<dependency>
<groupId>com.google.crypto.tink</groupId>
<artifactId>tink</artifactId>
<version>1.2.0-rc2</version>
</dependency>
阅读全文 »

注解实现动态锁业务

发表于 2022-04-23 | 更新于 2022-04-26 | 分类于 Java
| 字数: 7.1k | 时长 ≈ 6 分钟
标签 Lock spring Redis

概要

基于注解、Spring AOP 和 Spring Expression表达式实现动态锁业务。

阅读全文 »

Spring Boot 实现表单锁

发表于 2022-04-14 | 更新于 2024-01-12 | 分类于 Java
| 字数: 7.1k | 时长 ≈ 6 分钟
标签 redis spring-boot 分布式锁

通过注解和 SpEL 表达式实现表单动态锁业务

阅读全文 »

Spring Boot 全局异常处理

发表于 2022-04-14 | 更新于 2022-11-30 | 分类于 Java
| 字数: 11k | 时长 ≈ 10 分钟
标签 spring-boot

ControllerAdvice + ExceptionHandler

BaseExceptionHandler.java

阅读全文 »

etcd 使用

发表于 2022-03-20 | 更新于 2022-04-26 | 分类于 etcd
| 字数: 916 | 时长 ≈ 1 分钟
标签 etcd

部署

1
# 略
阅读全文 »
12…14
forever杨

forever杨

开心又过一日,唔开心又过一日

202 文章
31 分类
175 标签
GitHub
友情链接
  • Tidy的个人博客
© 2024 forever杨 | 站点总字数: 706k