Browse Source

supplement

admin 1 year ago
parent
commit
e1ede1ec3f

+ 56 - 0
serializableJava/src/main/java/org/example/jdkSerializable/Account.java

@@ -0,0 +1,56 @@
+package org.example.jdkSerializable;
+
+import java.io.Serializable;
+
+public class Account implements Serializable {
+    private static final long serialVersionUID = -547309094426427798L;
+    private Long id;
+    private String account;
+    // transient 作用是在序列化的时候忽略当前属性的值,可以屏蔽掉一些敏感或者没用的数据
+    // 可以从后面的验证结果输出的内容看到具体效果
+    transient private String password;
+    private String email;
+
+    public Long getId() {
+        return id;
+    }
+
+    public void setId(Long id) {
+        this.id = id;
+    }
+
+    public String getAccount() {
+        return account;
+    }
+
+    public void setAccount(String account) {
+        this.account = account;
+    }
+
+    public String getPassword() {
+        return password;
+    }
+
+    public void setPassword(String password) {
+        this.password = password;
+    }
+
+    public String getEmail() {
+        return email;
+    }
+
+    public void setEmail(String email) {
+        this.email = email;
+    }
+
+    //-----------省略get set 方法-----------
+    @Override
+    public String toString() {
+        return "Account{" +
+                "id=" + id +
+                ", account='" + account + '\'' +
+                ", password='" + password + '\'' +
+                ", email='" + email + '\'' +
+                '}';
+    }
+}

+ 44 - 0
serializableJava/src/main/java/org/example/jdkSerializable/SerializableUtil.java

@@ -0,0 +1,44 @@
+package org.example.jdkSerializable;
+
+import java.io.*;
+
+public class SerializableUtil {
+    /**
+     * 序列化方法
+     * @param obj
+     * @param fileName
+     * @throws IOException
+     */
+    public static void serialize(Object obj,String fileName) throws IOException {
+        FileOutputStream fos = new FileOutputStream(fileName);
+        ObjectOutputStream oos = new ObjectOutputStream(fos);
+        oos.writeObject(obj);
+        oos.close();
+        fos.close();
+    }
+    /**
+     * 反序列化方法
+     * @param fileName
+     * @return
+     * @throws Exception
+     */
+    public static Object deserialize(String fileName) throws Exception {
+        FileInputStream fis = new FileInputStream(fileName);
+        ObjectInputStream ois = new ObjectInputStream(fis);
+        Object object = ois.readObject();
+        ois.close();
+        fis.close();
+        return object;
+    }
+    public static void main(String[] args) throws Exception {
+        Account account = new Account();
+        account.setId(1L);
+        account.setAccount("chase");
+        account.setEmail("[email protected]");
+        account.setPassword("********");
+        serialize(account,"account");
+        Account result = (Account) deserialize("account");
+        System.out.println(account);
+        System.out.println(result);
+    }
+}

+ 14 - 0
undertowSpringBoot/src/main/java/org/example/HelloController.java

@@ -0,0 +1,14 @@
+package org.example;
+
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+@RestController
+public class HelloController {
+
+    @GetMapping("/hello")
+    public String getUserById() {
+
+        return "hello";
+    }
+}

+ 15 - 0
undertowSpringBoot/src/main/resources/application.yaml

@@ -0,0 +1,15 @@
+# 设置IO线程数, 它主要执行非阻塞的任务,它们会负责多个连接, 默认设置每个CPU核心一个线程
+# 不要设置过大,如果过大,启动项目会报错:打开文件数过多
+server:
+  undertow:
+    io-threads: 16
+    # 阻塞任务线程池, 当执行类似servlet请求阻塞IO操作, undertow会从这个线程池中取得线程
+    # 它的值设置取决于系统线程执行任务的阻塞系数,默认值是IO线程数*8
+    worker-threads: 256
+    # 以下的配置会影响buffer,这些buffer会用于服务器连接的IO操作,有点类似netty的池化内存管理
+    # 每块buffer的空间大小,越小的空间被利用越充分,不要设置太大,以免影响其他应用,合适即可
+    buffer-size: 1024
+    # 每个区分配的buffer数量 , 所以pool的大小是buffer-size * buffers-per-region
+    buffers-per-region: 1024
+    # 是否分配的直接内存(NIO直接分配的堆外内存)
+    direct-buffers: true