diff --git a/java_demo/src/main/java/com/cmower/java_demo/duoxiancheng/Cmower.java b/java_demo/src/main/java/com/cmower/java_demo/duoxiancheng/Cmower.java new file mode 100644 index 0000000000000000000000000000000000000000..f96a0e964635fdec43b7e9fedac78b3cf1a7f73f --- /dev/null +++ b/java_demo/src/main/java/com/cmower/java_demo/duoxiancheng/Cmower.java @@ -0,0 +1,39 @@ +package com.cmower.java_demo.duoxiancheng; + +import java.util.concurrent.ArrayBlockingQueue; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.ThreadPoolExecutor; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.atomic.AtomicInteger; + +public class Cmower { + + public static AtomicInteger count = new AtomicInteger(); + + public static int getCount() { + return count.get(); + } + + public static void addCount() { + count.incrementAndGet(); + } + + public static void main(String[] args) { + ExecutorService executorService = new ThreadPoolExecutor(10, 1000, 60L, TimeUnit.SECONDS, + new ArrayBlockingQueue(10)); + + for (int i = 0; i < 1000; i++) { + Runnable r = new Runnable() { + + @Override + public void run() { + Cmower.addCount(); + } + }; + executorService.execute(r); + } + executorService.shutdown(); + System.out.println(Cmower.count); + } + +} diff --git a/java_demo/src/main/java/com/cmower/java_demo/xuliehua/Test.java b/java_demo/src/main/java/com/cmower/java_demo/xuliehua/Test.java new file mode 100644 index 0000000000000000000000000000000000000000..ae9fbd4d81b9820e01dbf2dc749c94d8d96d29c3 --- /dev/null +++ b/java_demo/src/main/java/com/cmower/java_demo/xuliehua/Test.java @@ -0,0 +1,37 @@ +package com.cmower.java_demo.xuliehua; + +import java.io.File; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.ObjectInputStream; +import java.io.ObjectOutputStream; + +public class Test { + + public static void main(String[] args) { + // 初始化 + Wanger wanger = new Wanger(); + wanger.setName("王二"); + wanger.setAge(18); + System.out.println(wanger); + + // 把对象写到文件中 + try (ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream("chenmo"));){ + oos.writeObject(wanger); + } catch (IOException e) { + e.printStackTrace(); + } + + Wanger.pre ="不沉默"; + + // 从文件中读出对象 + try (ObjectInputStream ois = new ObjectInputStream(new FileInputStream(new File("chenmo")));){ + Wanger wanger1 = (Wanger) ois.readObject(); + System.out.println(wanger1); + } catch (IOException | ClassNotFoundException e) { + e.printStackTrace(); + } + } + +} diff --git a/java_demo/src/main/java/com/cmower/java_demo/xuliehua/Wanger.java b/java_demo/src/main/java/com/cmower/java_demo/xuliehua/Wanger.java new file mode 100644 index 0000000000000000000000000000000000000000..503c1a7ce0fa9375460a8690dca0d41ac083a18d --- /dev/null +++ b/java_demo/src/main/java/com/cmower/java_demo/xuliehua/Wanger.java @@ -0,0 +1,34 @@ +package com.cmower.java_demo.xuliehua; + +import java.io.Serializable; + +class Wanger implements Serializable { + private static final long serialVersionUID = -2095916884810199532L; + + private String name; + private int age; + + public static String pre = "沉默"; + transient String meizi = "王三"; + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public int getAge() { + return age; + } + + public void setAge(int age) { + this.age = age; + } + + @Override + public String toString() { + return "Wanger{" + "name=" + name + ",age=" + age + ",pre=" + pre + ",meizi=" + meizi + "}"; + } +}