1. 序列化
Serialization
Deserialization
import java.io.Serializable;
implements Serializable
import java.io.File
import java.io.FileOutputStream;
import java.io.ObjectOutputStream;
oos = new ObjectOutputStream(new FileOutputStream(new File(“xxx.txt”)));
oos.writeObject(ob);
import java.io.FileInputStream;
import java.io.ObjectInputStream;
ois = new ObjectInputStream(new FileInputStream(new File(“xxx.txt”)));
2. static
- 成员变量
- 成员函数
- 代码
- 内部类
- import static
3. synchronized
类锁
对象锁
monitor 对象
monitorEnter
monitorExit
4. volatile
可见性
有序性
无原子性
5. transient
临时变量
6.lock
ReentrantLock
import java.util.concurrent.
可重入锁
范围可控、trylock、性能
7. AtomicInteger
import java.util.concurrent.atomic.AtomicInteger
a.getAndIncrement();
8.AtomicReference
import java.util.concurrent.atomic.AtomicReference
AtomicReference ao = new AtomicReference<>(new Object());
ao.set();
ao.get()
ao.compareAndSet(compareObject, newObject);
9. Thread
import java.lang.Thread
import java.lang.Runnable;
new Thread(runnableObject).start();
@Override
void run(){
}
Thread.currentThread.getId
getName/setName
getPriority/setPriority
isDaemon/setDaemon 守护进程依赖其创建的进程
Thread.currentThread.sleep();
Thread.currentThread.yield() 释放cpu
isInterrupted/interrupt
join 等待其完成