This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Snowflake { | |
/** | |
* configured machine id - 10 bits - gives us up to 1024 machines | |
*/ | |
private static final int BITS_MACHINE_ID = 10; | |
/** | |
* sequence number - 12 bits - rolls over every 4096 per machine (with protection to avoid rollover in the same ms) | |
*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class VolatileTest { | |
public static boolean stop = false; // 该变量加上 volatile 后,主线程设置 stop = true 才会对 Reader 线程可见 | |
private static class Reader extends Thread { | |
@Override | |
public void run() { | |
// 期望:当主线程设置 stop = true 时,Reader 线程输出 stop 并结束 | |
// 实际:由于共享变量 stop 没有加 volatile,主线程设置 stop = true 对 Reader 线程不可见,所以 Reader 线程永远不会结束 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import org.springframework.boot.context.properties.bind.Binder; | |
import org.springframework.boot.context.properties.source.ConfigurationPropertySource; | |
import org.springframework.boot.context.properties.source.ConfigurationPropertySources; | |
import org.springframework.core.env.PropertiesPropertySource; | |
import java.util.Map; | |
import java.util.Properties; | |
public class PropertiesToNestedMap { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import okhttp3.OkHttpClient; | |
import javax.net.ssl.*; | |
import java.io.IOException; | |
import java.io.InputStream; | |
import java.security.*; | |
import java.security.cert.CertificateException; | |
import java.util.Arrays; | |
public class OkHttpMutualTLS { |