Guava
小于 1 分钟
Guava
缓存
@Configuration
public class GuavaCacheConfig {
@Bean(name = "codeCache")
public Cache<String, String> codeCache() {
return CacheBuilder.newBuilder()
.expireAfterWrite(3, TimeUnit.MINUTES)
.build();
}
}
布隆过滤器
public class ApiTest {
@Test
public void test_BloomFilter() {
BloomFilter<String> bloomFilter = BloomFilter.create(
Funnels.stringFunnel(Charset.defaultCharset()),
1000,
0.01);
bloomFilter.put("1001");
bloomFilter.put("1002");
bloomFilter.put("1003");
System.out.println(bloomFilter.mightContain("1001"));
System.out.println(bloomFilter.mightContain("1002"));
System.out.println(bloomFilter.mightContain("1003"));
System.out.println(bloomFilter.mightContain("1004"));
// 输出布隆过滤器的统计信息
System.out.println("Expected FPP: " + bloomFilter.expectedFpp());
System.out.println("Number of Inserted Elements: " + bloomFilter.approximateElementCount());
}
}
消息队列
@Slf4j
public class ApiTest {
@Test
public void test_eventbus() {
EventBus eventBus = new EventBus();
eventBus.register(new Listener());
eventBus.post("100001");
}
static class Listener {
@Subscribe
public void handleEvent(String orderId) {
log.info("测试结果:{}", orderId);
}
}
}