给定一个AtomicLong对象,将值递减增量的正确方法是什么?
选项1
AtomicLong count = new AtomicLong(0L);
public void decrementCount(long decrementBy) {
count.getAndUpdate(l->count.get() - decrementBy);
}
Run Code Online (Sandbox Code Playgroud)
选项2
AtomicLong count = new AtomicLong(0L);
public void decrementCount(long decrementBy) {
count.getAndAdd(-decrementBy);
}
Run Code Online (Sandbox Code Playgroud)
虽然两者都给出了所需的结果,但我想了解在什么情况下它们不会代表所需的行为,即原子地递减长值?(例如,第二种方法的一个缺点可能是负号导致一些位溢出,但我不确定这是否属实)
长话短说
\n\nSpring Bootserver.port中定义的属性在 Tomcat 中运行 Web 应用程序时,Docker 引擎不会遵循
背景 :
\n\n我有一个简单的 Spring Boot 应用程序,其中包含一个休息端点。我能够在 Eclipse 中运行此应用程序并从浏览器成功访问其余端点。
\n\n但是,当我尝试在 Docker 容器中部署相同的应用程序时,我无法从浏览器访问其余端点。
\n\nDockerfile:
\n\nFROM tomcat\nEXPOSE 8000\nRUN rm -rf /user/local/tomcat/webapps/*\nCOPY ./target/my-web-app.war /usr/local/tomcat/webapps/ROOT.war\nCMD ["catalina.sh","run"]\nRun Code Online (Sandbox Code Playgroud)\n\nSpring Boot application.properties :
\n\nspring.application.name=my-web-app\nserver.port=8000\nspring.jpa.show-sql=true\nspring.h2.console.enabled=true\nRun Code Online (Sandbox Code Playgroud)\n\nDocker 图像输出:
\n\nCK@Ping MINGW64 /c/Program Files/Docker Toolbox\n$ docker images\nREPOSITORY TAG IMAGE ID CREATED SIZE\nmyrepo/my-web-app 0.0.1-SNAPSHOT 625e9d889139 4 minutes ago 694MB\nRun Code Online (Sandbox Code Playgroud)\n\n启动容器:
\n\n请注意,我映射了Spring Bootserver.port的 application.properties映射到外部端口。
docker …Run Code Online (Sandbox Code Playgroud) 给定一个为其配置了实例列表的Spring Batch作业,JobExecutionListener每个侦听器的执行顺序是什么。例子 :
<job id="myJob" xmlns="http://www.springframework.org/schema/batch">
<batch:listeners>
<batch:listener ref="myJobExecutionListener1" />
<batch:listener ref="myJobExecutionListener2" />
<batch:listener ref="myJobExecutionListener3" />
<batch:listener ref="myJobExecutionListener4" />
</batch:listeners>
<!-- job config continues -->
</job>
Run Code Online (Sandbox Code Playgroud)
在上面的例子中,有没有保证监听器会按照配置的顺序执行,还是会按照随机的顺序执行。我尝试查看Spring Batch参考文档,但就我的研究而言,我找不到这个文档。