-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathAtomicRefenceDemo.java
More file actions
47 lines (39 loc) · 935 Bytes
/
AtomicRefenceDemo.java
File metadata and controls
47 lines (39 loc) · 935 Bytes
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
package com.bywlstudio.cas;
import java.util.concurrent.atomic.AtomicReference;
/**
* 原子引用实现
*/
class User{
String name ;
Integer id ;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
@Override
public String toString() {
return "User{" +
"name='" + name + '\'' +
", id=" + id +
'}';
}
public User(String name, Integer id) {
this.name = name;
this.id = id;
}
}
public class AtomicRefenceDemo {
public static void main(String[] args) {
AtomicReference<User> atomicReference = new AtomicReference<>();
atomicReference.set(new User("1",1));
System.out.println(atomicReference.get());
}
}