API 接口中的空数组怎么表示?
最近开发一个 API, 使用者说这个 API 中返回数组如果为空, 按照规范应该返回空数组[]
, 而我现在使用 Java 的 jackson-databind 返回的是 null
, 要问改成[]
.
最近开发一个 API, 使用者说这个 API 中返回数组如果为空, 按照规范应该返回空数组[]
, 而我现在使用 Java 的 jackson-databind 返回的是 null
, 要问改成[]
.
https://thestrangeloop.com/2017/the-performance-engineers-guide-to-java-hotspot-virtual-machines-execution-engine.html
这个视频其实和她的那本书基本是一致的, 加了些那年比较新的东西.
在 MAC 上工作, 竟然遇到要更改 PATH 环境变量的情况. 比如有的 Java 工程是基于 JDK8 的, 有的是基于 JDK11 的, 所以经常要改这个变量. 那么我们看到的 PATH 环境变量是从哪里来的, 那些配置文件会改这些 PATH 值呢?
首先, 我们先看下当前的 PATH 变量:
~ xiatian$ echo $PATH
/usr/local//Cellar/curl/7.80.0_1/bin/:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Applications/Wireshark.app/Contents/MacOS:/Users/xiatian/work/tools:/Applications/Visual\ Studio\ Code.app/Contents/Resources/app/bin/
这里面有好多路径, 那么我们好奇当系统启动的过程中, 最初的 PATH 是什么呢?
MAC 上最初的 PATH 是从 /etc/paths
文件读的:
~ xiatian$ cat /etc/paths
/usr/local/bin
/usr/bin
/bin
/usr/sbin
/sbin
然后, 它会把 /etc/path.d
里面的路径逐个添加到后面, 比如我们可以看到我的 wireshark 路径在上面的 PATH 里:
~ xiatian$ ls -l /etc/paths.d/
total 8
-rw-r--r-- 1 root wheel 43 Oct 19 2017 Wireshark
~ xiatian$ cat /etc/paths.d/Wireshark
/Applications/Wireshark.app/Contents/MacOS
.bash_profile
& .bash_rc
. 他们的区别是: 当一个 shell 是 login shell 的时候, 它会先执行 .bash_profile
, 当是一个非 login 交互式 shell 的时候, 它执行 .bashrc
. 但是在 MAC 上, 默认都是 login shell, 所以应该都执行. 来源于这个问答. 我试过了自带的 Terminal 和 安装的 iterm, 发现我的 MAC 都不是这么玩的.我本地是执行的 ~/.profile. 查看 bash 的 man, 你会在 INVOCATION section 看到具体的配置执行顺序:
~ xiatian$ man bash
When bash is invoked as an interactive login shell, or as a non-interactive shell with the --login option, it first reads and executes commands from the file /etc/profile, if that file exists. After reading that file, it looks for ~/.bash_profile, ~/.bash_login, and ~/.profile, in that order, and reads and executes commands from the first one that exists and is readable. The --noprofile option may be used when the shell is started to inhibit this behavior.
When an interactive shell that is not a login shell is started, bash reads and executes commands from ~/.bashrc, if that file exists. This may be inhibited by using the --norc option. The --rcfile file option will force bash to read and execute commands from file instead of ~/.bashrc.
所以, 只要仔细阅读 man bash
的内容, 你就知道 PATH 是怎么变化的啦.
一本简短的关于 Linux 虚拟化方面的书, 涉及到虚拟机和container的一些核心概念, 挺好的.
<<Linux Containers and Virtualization: A Kernel Perspective>>
VMM 基本功能:
内存虚拟化: guest OS 不能直接操作物理内存, 不能操作硬件 page tables. 一般Virtual Memory -> CR3 + MMU (硬件) -> 查找 page tables -> 物理内存; 对应 VMM 有了 3 层抽象
net namespace 相关的命令
1. ip netns add myns
2. ip netns del myns
3. ip netns exec myns sh ## 执行 sh 在 myns namespace
4. ip link add veth0 type veth peer name veth1 ##创建 veth 对 (veth0 ~ veth1)
5. ip link set veth1 netns myns ## 把 veth 的一端加到 myns namespace
CPU group:
Block I/O cgroup
Layered File System: