我已经快速阅读了Oracle Lambda Expression文档.
这种例子帮助我更好地理解了:
//Old way:
List<Integer> list = Arrays.asList(1, 2, 3, 4, 5, 6, 7);
for(Integer n: list) {
System.out.println(n);
}
//New way:
List<Integer> list = Arrays.asList(1, 2, 3, 4, 5, 6, 7);
list.forEach(n -> System.out.println(n));
//or we can use :: double colon operator in Java 8
list.forEach(System.out::println);
Run Code Online (Sandbox Code Playgroud)
不过,我不明白为什么会有这样的创新.它只是一种在"方法变量"结束时死亡的方法,对吗?为什么我应该使用它而不是真正的方法?在性能方面哪个是更好的选择.Lambda或简单的循环.
我已经快速阅读了Java8 String api文档.
现在我对String.join()方法很好奇,以便连接/连接字符串.
这种例子帮助我更好地理解了:
//Old way:
String str1 = "John";
String str2 = "Doe";
String result = str1 + " " +str2;
//or by using str1.concat(str2);
//New way:
String result = String.join(" ", str1, str2);
Run Code Online (Sandbox Code Playgroud)
不过,我不明白应该使用哪一个.这两个过程之间是否有任何性能或其他差异.
任何帮助将不胜感激.
我在docker 网络方面遇到了一个奇怪的问题。我在 Docker 容器中使用名为extenal_network的外部桥接网络,并启用了自动重启。如果任何容器由于某些错误(可能是代码或基础设施相关)而重新启动,我将无法访问我的主机网络。
请参阅随附的屏幕截图以获得更清晰的信息。
我已经尝试过以下链接,但没有运气。
Dockerfile
FROM node:10.20.1-alpine
RUN apk add --no-cache python make g++
WORKDIR /home/app
COPY package.json package-lock.json* ./
RUN npm install
COPY . .
Run Code Online (Sandbox Code Playgroud)
Docker-Compose
version: "3"
services:
app:
container_name: app
build:
context: ./
dockerfile: Dockerfile
image: 'network_poc:latest'
ports:
- 8080:8080
deploy:
resources:
limits:
memory: 2G
networks:
- extenal_network
restart: always
command: node index.js
networks:
shared_network:
external:
name: extenal_network
Run Code Online (Sandbox Code Playgroud)
docker 检查external_network
[
{
"Name": "extenal_network",
"Id": "96476c227ddc14aa23d376392d380b2674fcbad109c90e7436c0cddd5c0a9ac5", …Run Code Online (Sandbox Code Playgroud) networking google-chrome docker docker-compose docker-network
我正在从 Postgres 表中聚合数据,查询大约需要 2 秒,我想将其减少到不到一秒。
请在下面找到执行细节:
询问
select
a.search_keyword,
hll_cardinality( hll_union_agg(a.users) ):: int as user_count,
hll_cardinality( hll_union_agg(a.sessions) ):: int as session_count,
sum(a.total) as keyword_count
from
rollup_day a
where
a.created_date between '2018-09-01' and '2019-09-30'
and a.tenant_id = '62850a62-19ac-477d-9cd7-837f3d716885'
group by
a.search_keyword
order by
session_count desc
limit 100;
Run Code Online (Sandbox Code Playgroud)
表元数据
查询计划
Custom Scan (cost=0.00..0.00 rows=0 width=0) (actual time=1722.685..1722.694 rows=100 loops=1)
Task Count: 1
Tasks Shown: All
-> Task
Node: host=localhost port=5454 dbname=postgres
-> Limit (cost=64250.24..64250.49 …Run Code Online (Sandbox Code Playgroud) sql postgresql indexing query-performance postgresql-performance
我正在尝试在 Google - Guice 中实现基于 AOP 的日志记录。我已经用过MethodInterceptor这个但它不起作用。我在 Spring 中通过定义切入点来使用相同的方法。那里一切都运转良好。
基于 AOP 的日志记录的 Spring 代码 -
@Aspect
public class LoggingAspect {
private static Logger logger = LoggerFactory.getLogger(LoggingAspect.class);
@Around("requiredLog()")
public Object bentoBoxAround(ProceedingJoinPoint proceedingJoinPoint) {
Object returnValue = null;
try {
logger.info("Entered into the method -> " + proceedingJoinPoint.getSignature().toShortString()
+ " and input arguments are -> " + Arrays.asList(proceedingJoinPoint.getArgs()));
returnValue = proceedingJoinPoint.proceed();
logger.info("Method Execution over !! " + proceedingJoinPoint.getSignature().toShortString());
} catch (Throwable e) {
logger.error("Method has an exception " …Run Code Online (Sandbox Code Playgroud) public class App {
public static void main(String[] args) {
ConTest conTest = new ConTest(null);
}
Run Code Online (Sandbox Code Playgroud)
POJO:
public class ConTest {
private String a;
private Object b;
public ConTest(Object b) {
System.out.println("Object" + b);
}
public ConTest(String a) {
System.out.println("String :" + a);
}
}
Run Code Online (Sandbox Code Playgroud)
当我运行这段代码时,它总是调用带有String参数的构造函数.为什么?