diff --git a/week_04/42/ArrayBlockingQueueTest.java b/week_04/42/ArrayBlockingQueueTest.java new file mode 100644 index 0000000000000000000000000000000000000000..c4848bc4d0608a09800160864f5600937d1d05b7 --- /dev/null +++ b/week_04/42/ArrayBlockingQueueTest.java @@ -0,0 +1,20 @@ +package com.jdk.week4; + +import java.util.concurrent.ArrayBlockingQueue; + +/** + * Copyright + * + * @author conanju + * @since 2020/1/10 9:59 + */ +public class ArrayBlockingQueueTest { + public static void main(String[] args) throws InterruptedException { + ArrayBlockingQueue arrayBlockingQueue = new ArrayBlockingQueue<>(20); + arrayBlockingQueue.add("1"); + arrayBlockingQueue.add("2"); + arrayBlockingQueue.add("3"); + arrayBlockingQueue.take(); + arrayBlockingQueue.add("4"); + } +} diff --git a/week_04/42/ConcurrentHashMapTest.java b/week_04/42/ConcurrentHashMapTest.java new file mode 100644 index 0000000000000000000000000000000000000000..27df427ef085ec83355fb443e357562f75f6e255 --- /dev/null +++ b/week_04/42/ConcurrentHashMapTest.java @@ -0,0 +1,24 @@ +package com.jdk.week4; + +import java.util.HashMap; + +/** + * Copyright + * + * @author conanju + * @since 2020/1/6 15:55 + */ +public class ConcurrentHashMapTest { + public static void main(String[] args) { + HashMap hashMap = new HashMap<>(); + hashMap.put("1","1"); + System.out.println(hashMap.get("1")); + hashMap.putIfAbsent("1","2"); + System.out.println(hashMap.get("1")); + hashMap.put("1","2"); + System.out.println(hashMap.get("1")); + System.out.println(Float.isNaN(0.1F)); + } + + +} diff --git a/week_04/42/ConcurrentLinkedQueueTest.java b/week_04/42/ConcurrentLinkedQueueTest.java new file mode 100644 index 0000000000000000000000000000000000000000..d534adb816db70ee4fc77f657b12536d9360fdde --- /dev/null +++ b/week_04/42/ConcurrentLinkedQueueTest.java @@ -0,0 +1,19 @@ +package com.jdk.week4; + +import java.util.ArrayList; +import java.util.concurrent.ConcurrentLinkedQueue; + +/** + * Copyright + * + * @author conanju + * @since 2020/1/10 13:57 + */ +public class ConcurrentLinkedQueueTest { + public static void main(String[] args) { + ArrayList arrayList = new ArrayList(); + arrayList.add(null); + ConcurrentLinkedQueue concurrentLinkedQueue = new ConcurrentLinkedQueue<>(); + concurrentLinkedQueue.add(null); + } +} diff --git a/week_04/42/CopyOnWriteArrayListTest.java b/week_04/42/CopyOnWriteArrayListTest.java index 9732ec68106dd3931ed108060ef6fac3a01f348d..143b066c95a8cf58ea630f4069d671a2c18f7220 100644 --- a/week_04/42/CopyOnWriteArrayListTest.java +++ b/week_04/42/CopyOnWriteArrayListTest.java @@ -1,76 +1,76 @@ -package com.jdk.week4; - -import java.util.Objects; -import java.util.concurrent.CopyOnWriteArrayList; - -/** - * Copyright - * - * @author conanju - * @since 2020/1/5 11:19 - */ -public class CopyOnWriteArrayListTest { - public static void main(String[] args) { - Person person = new Person(10, "conan", 20.3); - Person person1 = new Person(20, "jmas", 30.3); - Person person2 = new Person(10, "conan", 20.3); - System.out.println(person == person1); - Person[] people = {person, person1, person2}; - CopyOnWriteArrayList arrayList = new CopyOnWriteArrayList(people); - System.out.println(arrayList.contains(person)); - - arrayList.remove(1); - - } -} - -class Person { - int age; - String name; - double salary; - - public Person(int age, String name, double salary) { - this.age = age; - this.name = name; - this.salary = salary; - } - - public int getAge() { - return age; - } - - public void setAge(int age) { - this.age = age; - } - - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } - - public double getSalary() { - return salary; - } - - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - Person person = (Person) o; - return age == person.age && - Double.compare(person.salary, salary) == 0 && - Objects.equals(name, person.name); - } - - @Override - public int hashCode() { - return Objects.hash(age, name, salary); - } - - public void setSalary(double salary) { - this.salary = salary; - } -} +package com.jdk.week4; + +import java.util.Objects; +import java.util.concurrent.CopyOnWriteArrayList; + +/** + * Copyright + * + * @author conanju + * @since 2020/1/5 11:19 + */ +public class CopyOnWriteArrayListTest { + public static void main(String[] args) { + Person person = new Person(10, "conan", 20.3); + Person person1 = new Person(20, "jmas", 30.3); + Person person2 = new Person(10, "conan", 20.3); + System.out.println(person == person1); + Person[] people = {person, person1, person2}; + CopyOnWriteArrayList arrayList = new CopyOnWriteArrayList(people); + System.out.println(arrayList.contains(person)); + + arrayList.remove(1); + + } +} + +class Person { + int age; + String name; + double salary; + + public Person(int age, String name, double salary) { + this.age = age; + this.name = name; + this.salary = salary; + } + + public int getAge() { + return age; + } + + public void setAge(int age) { + this.age = age; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public double getSalary() { + return salary; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + Person person = (Person) o; + return age == person.age && + Double.compare(person.salary, salary) == 0 && + Objects.equals(name, person.name); + } + + @Override + public int hashCode() { + return Objects.hash(age, name, salary); + } + + public void setSalary(double salary) { + this.salary = salary; + } +} diff --git a/week_04/42/DelayQueueTest.java b/week_04/42/DelayQueueTest.java new file mode 100644 index 0000000000000000000000000000000000000000..5dcd31a92702965a81c62660b1033f6116c84e15 --- /dev/null +++ b/week_04/42/DelayQueueTest.java @@ -0,0 +1,16 @@ +package com.jdk.week4; + +import java.util.concurrent.DelayQueue; + +/** + * Copyright + * + * @author conanju + * @since 2020/1/10 23:03 + */ +public class DelayQueueTest { + public static void main(String[] args) { + DelayQueue delayQueue = new DelayQueue(); + delayQueue.add() + } +} diff --git a/week_04/42/HashMapTest.java b/week_04/42/HashMapTest.java new file mode 100644 index 0000000000000000000000000000000000000000..79986de3198bb80c32c546ce058d8169e2dce50c --- /dev/null +++ b/week_04/42/HashMapTest.java @@ -0,0 +1,33 @@ +package com.jdk.week4; + +import java.util.HashMap; +import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; + +/** + * Copyright + * + * @author conanju + * @since 2020/1/9 11:04 + */ +public class HashMapTest { + public static void main(String[] args) { + HashMap map = new HashMap<>(); + System.out.println(map.put("name", "conanju")); + ; + System.out.println(map.put(null, "conanju")); + ; + System.out.println(map.putIfAbsent("name", "233")); + System.out.println(map.get("name")); + System.out.println(map.put("name", "洗衣机")); + System.out.println(map.get("name")); + } + +private static final Map map = new ConcurrentHashMap(); +public void unsafeUpdate(Integer key, String value) { + String oldValue = map.get(key); + if (oldValue == null) { + map.put(key, value); + } +} +} diff --git a/week_04/42/resources/ArrayBlockingQueue.xmind b/week_04/42/resources/ArrayBlockingQueue.xmind new file mode 100644 index 0000000000000000000000000000000000000000..7baca0a3c64331e1262aa7ed20394300190706f6 Binary files /dev/null and b/week_04/42/resources/ArrayBlockingQueue.xmind differ diff --git a/week_04/42/resources/ConcurrentHashMap.xmind b/week_04/42/resources/ConcurrentHashMap.xmind new file mode 100644 index 0000000000000000000000000000000000000000..bbe7ff0ac2f17ce0defc95a8c5cc9855d8066e09 Binary files /dev/null and b/week_04/42/resources/ConcurrentHashMap.xmind differ diff --git a/week_04/42/resources/ConcurrentLinkedQueue.xmind b/week_04/42/resources/ConcurrentLinkedQueue.xmind new file mode 100644 index 0000000000000000000000000000000000000000..baaf006e38f019624e1cfaa1aeb4034a6f953fdc Binary files /dev/null and b/week_04/42/resources/ConcurrentLinkedQueue.xmind differ diff --git a/week_04/42/resources/CopyOnWriteArrayList.png b/week_04/42/resources/CopyOnWriteArrayList.png new file mode 100644 index 0000000000000000000000000000000000000000..180b34421b39d6d9a7d07e4df1f84a46554fe65d Binary files /dev/null and b/week_04/42/resources/CopyOnWriteArrayList.png differ diff --git a/week_04/42/CopyOnWriteArrayList.xmind b/week_04/42/resources/CopyOnWriteArrayList.xmind similarity index 100% rename from week_04/42/CopyOnWriteArrayList.xmind rename to week_04/42/resources/CopyOnWriteArrayList.xmind diff --git a/week_04/42/resources/CopyOnWriteArrayList_ALL.png b/week_04/42/resources/CopyOnWriteArrayList_ALL.png new file mode 100644 index 0000000000000000000000000000000000000000..06d046a72ece17e94248276395e2c4b52b0336ce Binary files /dev/null and b/week_04/42/resources/CopyOnWriteArrayList_ALL.png differ diff --git a/week_04/42/resources/DelayQueue.xmind b/week_04/42/resources/DelayQueue.xmind new file mode 100644 index 0000000000000000000000000000000000000000..1b99025636226d02f2f52a6247ce0d6cc6ab1489 Binary files /dev/null and b/week_04/42/resources/DelayQueue.xmind differ diff --git "a/week_04/42/resources/\344\270\276\344\276\2131_\345\217\230\350\211\262.jpg" "b/week_04/42/resources/\344\270\276\344\276\2131_\345\217\230\350\211\262.jpg" new file mode 100644 index 0000000000000000000000000000000000000000..e2d781e141da3f856cfd39cdf913ee20561ac110 Binary files /dev/null and "b/week_04/42/resources/\344\270\276\344\276\2131_\345\217\230\350\211\262.jpg" differ diff --git "a/week_04/42/resources/\344\270\276\344\276\2132_\345\267\246\346\227\213.jpg" "b/week_04/42/resources/\344\270\276\344\276\2132_\345\267\246\346\227\213.jpg" new file mode 100644 index 0000000000000000000000000000000000000000..3354e3a61ed56e7e62a4f466f2e61d140b4205d1 Binary files /dev/null and "b/week_04/42/resources/\344\270\276\344\276\2132_\345\267\246\346\227\213.jpg" differ diff --git "a/week_04/42/resources/\344\270\276\344\276\2133_\345\217\263\346\227\213.jpg" "b/week_04/42/resources/\344\270\276\344\276\2133_\345\217\263\346\227\213.jpg" new file mode 100644 index 0000000000000000000000000000000000000000..f0c238ddd2198c6f6f0be1b9fffd5755a72f03b1 Binary files /dev/null and "b/week_04/42/resources/\344\270\276\344\276\2133_\345\217\263\346\227\213.jpg" differ diff --git "a/week_04/42/resources/\344\270\276\344\276\213_1_\346\217\222\345\205\245\350\212\202\347\202\2716.jpg" "b/week_04/42/resources/\344\270\276\344\276\213_1_\346\217\222\345\205\245\350\212\202\347\202\2716.jpg" new file mode 100644 index 0000000000000000000000000000000000000000..4376c471e6f42dec8ba517bb8076326443c00d85 Binary files /dev/null and "b/week_04/42/resources/\344\270\276\344\276\213_1_\346\217\222\345\205\245\350\212\202\347\202\2716.jpg" differ diff --git "a/week_04/42/resources/\345\217\263\346\227\213.gif" "b/week_04/42/resources/\345\217\263\346\227\213.gif" new file mode 100644 index 0000000000000000000000000000000000000000..997be0429268cb2efe4309c590feba3de4ab5382 Binary files /dev/null and "b/week_04/42/resources/\345\217\263\346\227\213.gif" differ diff --git "a/week_04/42/resources/\345\267\246\346\227\213.gif" "b/week_04/42/resources/\345\267\246\346\227\213.gif" new file mode 100644 index 0000000000000000000000000000000000000000..706d5ae1d9775d17145bda7f70e1ffd8fb8d5aef Binary files /dev/null and "b/week_04/42/resources/\345\267\246\346\227\213.gif" differ diff --git "a/week_04/42/resources/\346\225\260\346\215\256\347\273\223\346\236\204.xmind" "b/week_04/42/resources/\346\225\260\346\215\256\347\273\223\346\236\204.xmind" new file mode 100644 index 0000000000000000000000000000000000000000..7705e7b4f13eefe61a0da0513b89b9ba67a5becb Binary files /dev/null and "b/week_04/42/resources/\346\225\260\346\215\256\347\273\223\346\236\204.xmind" differ