为什么如果我从指针中减去另一个没有类型转换结果的指针(整数指针)将是1而不是4个字节(就像我将这两个指针强制转换为int时).示例:
int a , b , *p , *q;
p = &b;
q = p + 1; // q = &a;
printf("%d",q - p); // The result will be one .
printf("%d",(int)q - (int)p); // The result will be 4(bytes). The memory address of b minus The memory address of a.
Run Code Online (Sandbox Code Playgroud) 最近我试图实现一个电子邮件服务,同时向每个用户发送电子邮件。我当前的实现电流如下所示:
ExecutorService executor = Executors.newSingleThreadExecutor();
tasks.forEach(executor::execute); // Each task sends an email to an user
executorService.shutdown(); // Reclaim all the resources
Run Code Online (Sandbox Code Playgroud)
经过一番研究,我找到了一种新方法,即使用 Java 8CompletableFuture.runAsync(...)方法。使用这种方法我做了:
ExecutorService executor = Executors.newSingleThreadExecutor();
tasks.forEach(task -> CompletableFuture.runAsync(task, executor));
executor.shutdown(); // Reclaim all resources
Run Code Online (Sandbox Code Playgroud)
现在我有点困惑,就正确性、可扩展性而言,解决我的问题的最佳方法是什么,以及解决我的问题的最现代/当前的方法是什么。