0%

1
2
3
4
5
6
7
8
mv /etc/apt/sources.list /etc/apt/sources.list.bak
echo "deb http://mirrors.163.com/debian/ jessie main non-free contrib" >> /etc/apt/sources.list
echo "deb http://mirrors.163.com/debian/ jessie-proposed-updates main non-free contrib" >>/etc/apt/sources.list
echo "deb-src http://mirrors.163.com/debian/ jessie main non-free contrib" >>/etc/apt/sources.list
echo "deb-src http://mirrors.163.com/debian/ jessie-proposed-updates main non-free contrib" >>/etc/apt/sources.list
#更新安装源
apt-get update
apt-get install vim

内存不够,需要改配置并重启服务器

vim /etc/sysctl.conf

//在最后一行上加上

vm.max_map_count=262144

postgresql问题

fixing permissions on existing directory /var/lib/postgresql/data … ok
creating subdirectories … ok
selecting default max_connections … 100
selecting default shared_buffers … 128MB
selecting dynamic shared memory implementation … posix
creating configuration files … ok
LOG: could not link file “pg_xlog/xlogtemp.22” to “pg_xlog/000000010000000000000001”: Operation not permitted
FATAL: could not open file “pg_xlog/000000010000000000000001”: No such file or directory
child process exited with exit code 1
initdb: removing contents of data directory “/var/lib/postgresql/data”
creating template1 database in /var/lib/postgresql/data/base/1 … The files belonging to this database system will be owned by user “postgres”.
This user must also own the server process.

报错not permitted

需要在docker新建一个持久化volume

创建Volume虚拟磁盘:docker volume create –name <名称>

删除Volume虚拟磁盘:docker volume rm <名称>

  1. docker volume create *–name postgresql
  2. docker run –name mongodb -v postgresql:/data/db -p 27017:27017 -d postgresql

java对于切”.”这个值要转义”\.“

1
String[] split = midS.split("\\.");

简单工厂模式

image-20200606200444205

image-20200606200524558

优点

只需要传入一个正确的参数,就可以获取你所需要的对象,而无需知道其创建细节

缺点

工厂类职责相对过重,增加新的产品,需要修改工厂类的判断逻辑,违背开闭原则。、

UML

image-20200606201214011

工厂模式

工厂方法-定义和类型

定义:定义一个创建对象的接口,但让实现这个接口的类来决定实例化哪个类,工厂方法让类的实例化推迟到子类中实现。

类型:创建型。

适用场景

1.创建对象需要大量重复的代码

2.客户端(应用层)不依赖于产品类实例如何被创建,实现等细节

3.一个类通过其子类来指定创建哪个对象。

优点

1.用户只需要关心所需产品对应的工厂,无需关心创建细节。

2.加入新产品符合开闭原则,提高可扩展性。

缺点

1.类的个数容易过多,增加复杂度

2.增加了类的抽象性和理解难度

UML

image-20200606202621838

抽象工厂

image-20200606202715149

image-20200606202740380

image-20200606202758596

image-20200606202814677

工厂方法和抽象工厂

工厂方法是一个产品等级,抽象工厂是一个产品族。

比如美的空调,格力空调,松下空调是一个产品等级。

美的空调,美的洗衣机,美的冰箱,美的电饭煲则是一个产品族。

image-20200606203004204

浅克隆

对于浅克隆,对象是克隆了,但是里面的类确实用的同一个,示例如下:

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
/**
* @author xixing
* @version 1.0
* @date 2020/6/2 19:08
*/
public class Pig implements Cloneable {


private String name;
private Date birthday;

public Pig(String name, Date birthday) {
this.name = name;
this.birthday = birthday;
}

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

public Date getBirthday() {
return birthday;
}

public void setBirthday(Date birthday) {
this.birthday = birthday;
}

@Override
public String toString() {
return "Pig{" +
"name='" + name + '\'' +
", birthday=" + birthday +
'}'+super.toString();
}

@Override
protected Object clone() throws CloneNotSupportedException {
return super.clone();
}
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
/**
* @author xixing
* @version 1.0
* @date 2020/6/2 19:12
*/
public class Test {
public static void main(String[] args) throws CloneNotSupportedException {
Date birthday=new Date(0);
Pig pig1=new Pig("佩奇",birthday);
Pig pig2= (Pig) pig1.clone();
System.out.println(pig1);
System.out.println(pig2);
pig1.getBirthday().setTime(4839480394034L);
System.out.println(pig1);
System.out.println(pig2);

}
}

输出

image-20200602192237120

深克隆

1
2
3
4
5
6
7
@Override
protected Object clone() throws CloneNotSupportedException {
Pig pig= (Pig) super.clone();
//深克隆
pig.birthday= (Date) pig.birthday.clone();
return pig;
}

image-20200602192654029

对克隆的反射攻击破坏单例模式

1
2
3
4
5
6
HungrySingleton hungrySingleton=HungrySingleton.getInstance();
Method method = hungrySingleton.getClass().getDeclaredMethod("clone");
method.setAccessible(true);
HungrySingleton hungrySingleton1 = (HungrySingleton) method.invoke(hungrySingleton);
System.out.println(hungrySingleton);
System.out.println(hungrySingleton1);

解决方案

1
2
3
4
@Override
protected Object clone() throws CloneNotSupportedException {
return getInstance();
}

或者不实现Cloneable