0%

安装docker(Centos 8)

yum-config-manager –add-repo https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo

yum install -y yum-utils device-mapper-persistent-data lvm2
yum install -y containerd.io

yum install -y docker-ce –nobest

这个过程借鉴博客:https://blog.csdn.net/peizhelun/article/details/104435856/

systemctl enable docker

安装mysql

docker pull mysql:5.7

docker run -d -p 3306:3306 –name mymysql -e MYSQL_ROOT_PASSWORD=123456 d589ea3123e0

安装es

docker pull elasticsearch:6.6.2

docker run -d –name elasticsearch -p 9200:9200 -p 9300:9300 -e “discovery.type=single-node” 1bca39c5a102

docker run -d –name elasticsearch -p 9200:9200 -p 9300:9300 -e ES_JAVA_OPTS=”-Xms256m -Xmx256m” 1bca39c5a102

es的分页从第0页开始,而不是第1页

es在docker里面的参数修改

find /var/lib/docker/overlay2/ -name jvm.options

在找到的路径里改

安装rabbitmq

docker pull rabbitmq:3.7.7-management

docker run -d –name rabbitmq3.7.7 -p 5672:5672 -p 15672:15672 –hostname myRabbit -e RABBITMQ_DEFAULT_VHOST=my_vhost -e RABBITMQ_DEFAULT_USER=root -e RABBITMQ_DEFAULT_PASS=jx172020 2888deb59dfc

1
rabbitmqctl eval 'rabbit_amqqueue:declare({resource, <<"/">>, queue, <<"payNotify">>}, true, false, [], none).'

安装nginx

wget https://imcfile.oss-cn-beijing.aliyuncs.com/shizhan/file/liaoshixiong/nginx-1.16.1.tar.gz

tar -zxvf nginx-1.16.1.tar.gz -C /opt/module

进入目录下

cd /opt/module/nginx-1.16.1

配置安装目录

./configure –prefix=/usr/local/nginx

yum install -y zlib-devel openssl openssl-devel pcre-devel

1
2
3
4
location / {
root web;
index index.html index.htm;
}
location /admin {
    alias   admin;
    index  index.html index.htm;
}

Linux命令

ps - ef|grep java

查看Java进程

死锁

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
/**
* @author xixing
* @version 1.0
* @date 2020/7/16 10:52
*
* 死锁是两个及以上线程在执行过程中抢夺资源造成的现象
*
*/
public class DeadLockDemo {

public static void main(String[] args) {
String resourseA="resourseA";
String resourseB="resourseB";

new Thread(new HoldLockThread(resourseA,resourseB),"ThreadA").start();
new Thread(new HoldLockThread(resourseB,resourseA),"ThreadB").start();

/**
* linux ps -ef|grep xxx ls -l
*
* windows下也有类型ps的查看进程命令,但是只要看java进程
* 可以用 jps =java ps jps -l
* jstack 28087
*
*/
}
}

class HoldLockThread implements Runnable{

private String resourseA;
private String resourseB;
Lock lock=new ReentrantLock();

public HoldLockThread(String resourseA, String resourseB) {
this.resourseA = resourseA;
this.resourseB = resourseB;
}

@Override
public void run() {

synchronized (resourseA){
System.out.println(Thread.currentThread().getName()+"\t 自己持有"+resourseA+"尝试获得\t"+resourseB);
try {
TimeUnit.SECONDS.sleep(2);
} catch (InterruptedException e) {
e.printStackTrace();
}
synchronized (resourseB){

}

}


}

}

JVM体系结构

image-20200716150240537

复制算法

image-20200716150805511

标记回收算法

image-20200716150938448

标记-压缩算法

image-20200716151050963

GC

image-20200716154615745

image-20200716155613501

Boolean类型

image-20200716155853350

image-20200716191714321

example:

​ -XX:+PrintGCDetails

KV设值类型

MetaspaceSize是元空间大小

image-20200716192613458

MaxTenuringThreshold是多少次之后就是老年期

jinfo

image-20200716193154444

jinfo -flags 5678

可以把5678这个进程号的全部参数打印

image-20200716193603868

image-20200716193825356

查看JVM初始家底

java -XX:+PrintFlagsInitial

image-20200716194747078

java -XX:+PrintFlagsFinal =代表默认 :=代表修改后的值

image-20200716200329963

-Xms 启动时最小内存

-Xmx 最大内存

-Xss 单个线程最大栈空间

image-20200726093142620

为0则为默认值,在不同系统,默认值不一样,在linux,os x,unix的64位系统中为1024k,在windows则取决于你的虚拟内存大小。

image-20200726093318262

image-20200726094950180

image-20200726095356376

-XX:+PrintGCDetails -XX:MetaspaceSize=128m -XX:SurvivorRatio=4 -XX:NewRatio=4

-XX:+PrintGCDetails

查看gc详情

GC在青春期,FullGC在养老区

[GC (Allocation Failure) [PSYoungGen: 1752K->488K(2560K)] 1752K->664K(9728K), 0.0018961 secs] [Times: user=0.00 sys=0.00, real=0.00 secs]
[GC (Allocation Failure) [PSYoungGen: 488K->496K(2560K)] 664K->716K(9728K), 0.0015663 secs] [Times: user=0.00 sys=0.00, real=0.00 secs]
[Full GC (Allocation Failure) [PSYoungGen: 496K->0K(2560K)] [ParOldGen: 220K->629K(7168K)] 716K->629K(9728K), [Metaspace: 3216K->3216K(1056768K)], 0.0066899 secs] [Times: user=0.02 sys=0.00, real=0.01 secs]
[GC (Allocation Failure) [PSYoungGen: 0K->0K(2560K)] 629K->629K(9728K), 0.0004493 secs] [Times: user=0.00 sys=0.00, real=0.00 secs]
[Full GC (Allocation Failure) [PSYoungGen: 0K->0K(2560K)] [ParOldGen: 629K->611K(7168K)] 629K->611K(9728K), [Metaspace: 3216K->3216K(1056768K)], 0.0068001 secs] [Times: user=0.00 sys=0.00, real=0.01 secs]
Exception in thread “main” java.lang.OutOfMemoryError: Java heap space
at tech.xixing.jvm.HelloGC.main(HelloGC.java:15)
Heap
PSYoungGen total 2560K, used 57K [0x00000000ffd00000, 0x0000000100000000, 0x0000000100000000)
eden space 2048K, 2% used [0x00000000ffd00000,0x00000000ffd0e588,0x00000000fff00000)
from space 512K, 0% used [0x00000000fff00000,0x00000000fff00000,0x00000000fff80000)
to space 512K, 0% used [0x00000000fff80000,0x00000000fff80000,0x0000000100000000)
ParOldGen total 7168K, used 611K [0x00000000ff600000, 0x00000000ffd00000, 0x00000000ffd00000)
object space 7168K, 8% used [0x00000000ff600000,0x00000000ff698f48,0x00000000ffd00000)
Metaspace used 3247K, capacity 4496K, committed 4864K, reserved 1056768K
class space used 353K, capacity 388K, committed 512K, reserved 1048576K

Process finished with exit code 1

image-20200726100432380

image-20200726100811177

image-20200726100841373

-XX:SurvivorRatio

image-20200726101245549

默认XX:SurvivorRatio=8

eden space 53248K, 8% used [0x0000000780980000,0x0000000780dab0f0,0x0000000783d80000)
from space 6144K, 0% used [0x0000000784380000,0x0000000784380000,0x0000000784980000)
to space 6144K, 0% used [0x0000000783d80000,0x0000000783d80000,0x0000000784380000)

XX:SurvivorRatio=4

PSYoungGen total 54784K, used 4404K [0x0000000780980000, 0x0000000784980000, 0x00000007c0000000)
eden space 44032K, 10% used [0x0000000780980000,0x0000000780dcd328,0x0000000783480000)
from space 10752K, 0% used [0x0000000783f00000,0x0000000783f00000,0x0000000784980000)
to space 10752K, 0% used [0x0000000783480000,0x0000000783480000,0x0000000783f00000)

-XX:NewRatio

image-20200726102239095

image-20200726102133054

Heap
PSYoungGen total 54784K, used 4404K [0x0000000780980000, 0x0000000784980000, 0x00000007c0000000)
eden space 44032K, 10% used [0x0000000780980000,0x0000000780dcd328,0x0000000783480000)
from space 10752K, 0% used [0x0000000783f00000,0x0000000783f00000,0x0000000784980000)
to space 10752K, 0% used [0x0000000783480000,0x0000000783480000,0x0000000783f00000)
ParOldGen total 131072K, used 0K [0x0000000701c00000, 0x0000000709c00000, 0x0000000780980000)
object space 131072K, 0% used [0x0000000701c00000,0x0000000701c00000,0x0000000709c00000)
Metaspace used 3222K, capacity 4496K, committed 4864K, reserved 1056768K
class space used 350K, capacity 388K, committed 512K, reserved 1048576K

新生代和老年代分别为54784K和131072K符合1:2

-XX:MaxTenuringThreshold

进入养老区的次数

image-20200726103133188

image-20200726103058024

数值必须在0-15之间

image-20200726103345729

image-20200726103449775

常用jvm参数

image-20200726103552176

image-20200715191843710

ThreadPoolExecutor

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
public static ExecutorService newFixedThreadPool(int nThreads) {
return new ThreadPoolExecutor(nThreads, nThreads,
0L, TimeUnit.MILLISECONDS,
new LinkedBlockingQueue<Runnable>());
}

public static ExecutorService newSingleThreadExecutor() {
return new FinalizableDelegatedExecutorService
(new ThreadPoolExecutor(1, 1,
0L, TimeUnit.MILLISECONDS,
new LinkedBlockingQueue<Runnable>()));
}
public static ExecutorService newCachedThreadPool() {
return new ThreadPoolExecutor(0, Integer.MAX_VALUE,
60L, TimeUnit.SECONDS,
new SynchronousQueue<Runnable>());
}


public ThreadPoolExecutor(int corePoolSize,
int maximumPoolSize,
long keepAliveTime,
TimeUnit unit,
BlockingQueue<Runnable> workQueue,
ThreadFactory threadFactory,
RejectedExecutionHandler handler)

image-20200715203802156

线程池底层工作原理

image-20200715204145068

image-20200715204741765

image-20200715205055954

image-20200715205330067

CPU密集型配线程数

image-20200716104045232

IO密集型配线程数

1.尽可能配多线程,比如说CPU核数*2

2.

image-20200716104500443

整合阿里云oss实现文件上传

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
package tech.xixing.machineprice.service.impl;

import com.aliyun.oss.OSS;
import com.aliyun.oss.OSSClientBuilder;
import org.apache.commons.lang.StringEscapeUtils;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;
import tech.xixing.machineprice.service.OssService;
import tech.xixing.machineprice.utils.RandomString;
import tech.xixing.machineprice.vo.ResponseVO;

import java.io.ByteArrayInputStream;
import java.io.IOException;

/**
* @author xixing
* @version 1.0
* @date 2020/7/11 10:46
*/
@Service
public class OssServiceImpl implements OssService {

@Value("${aliyun.oss.accessKeyId}")
private String ACCESS_KEY_ID;

@Value("${aliyun.oss.accessKeySecret}")
private String ACCESS_KEY_SECRET;

@Value("${aliyun.oss.endpoint}")
private String ENDPOINT;

@Value("${aliyun.oss.bucketName}")
private String BUCKETNAME;


@Override
public ResponseVO<String> uploadFile(MultipartFile file) {
OSS ossClient= new OSSClientBuilder().build(ENDPOINT,ACCESS_KEY_ID,ACCESS_KEY_SECRET);
String originalFilename = file.getOriginalFilename();
String[] split = originalFilename.split("\\.");

String name = RandomString.getRandomString(15)+"."+split[split.length-1];
try {
ossClient.putObject(BUCKETNAME,"instrument/"+name,new ByteArrayInputStream(file.getBytes()));
} catch (IOException e) {
e.printStackTrace();
}
ossClient.shutdown();
String res = StringEscapeUtils.escapeHtml("http://"+BUCKETNAME+"."+ENDPOINT+"/instrument/"+name);
return ResponseVO.successByData(res);
}
}

对于刚生成的id,如果需要用到的话

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
<insert id="insertSelective" parameterType="tech.xixing.machineprice.pojo.Manufactor" useGeneratedKeys="true" keyProperty="id">
insert into manufactor
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="id != null">
id,
</if>
<if test="name != null">
name,
</if>
<if test="createTime != null">
create_time,
</if>
<if test="updateTime != null">
update_time,
</if>
<if test="sortedOrder != null">
sorted_order,
</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="id != null">
#{id,jdbcType=INTEGER},
</if>
<if test="name != null">
#{name,jdbcType=VARCHAR},
</if>
<if test="createTime != null">
#{createTime,jdbcType=TIMESTAMP},
</if>
<if test="updateTime != null">
#{updateTime,jdbcType=TIMESTAMP},
</if>
<if test="sortedOrder != null">
#{sortedOrder,jdbcType=INTEGER},
</if>
</trim>
</insert>

useGeneratedKeys=”true” keyProperty=”id”加上这两句,就可以在原来对象中写入这个id。

#{}使用的是预编译对应JDBC中的PreparedStatement

${}mybatis不会修改或者转义字符串,直接输出变量值

使用#{}可以防止sql注入

使用#{}包裹的语句会加上单引号

会使得部分语句失效

如创建mysql表的时候,只能使用${}

1
2
3
4
5
6
7
8
9
10
<update id="createByTableName" >
create table ${CreateTable.tableName} (
id int(11) ,
<foreach collection="CreateTable.tableList" index="index" item="item">
${ item } varchar(64) ,
</foreach>
PRIMARY KEY (id)

);
</update>