小编Pin*_*ing的帖子

将 AtomicLong 递减一定增量的正确方法

给定一个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)

虽然两者都给出了所需的结果,但我想了解在什么情况下它们不会代表所需的行为,即原子地递减长值?(例如,第二种方法的一个缺点可能是负号导致一些位溢出,但我不确定这是否属实)

java multithreading atomic

3
推荐指数
1
解决办法
878
查看次数

Windows 上的 Docker 引擎会忽略 Spring Boot Web 应用程序的 server.port 属性

长话短说

\n\n

Spring Bootserver.port中定义的属性在 Tomcat 中运行 Web 应用程序时,Docker 引擎不会遵循

\n\n
\n\n

背景 :

\n\n

我有一个简单的 Spring Boot 应用程序,其中包含一个休息端点。我能够在 Eclipse 中运行此应用程序并从浏览器成功访问其余端点。

\n\n

但是,当我尝试在 Docker 容器中部署相同的应用程序时,我无法从浏览器访问其余端点。

\n\n

Dockerfile:

\n\n
FROM 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"]\n
Run Code Online (Sandbox Code Playgroud)\n\n

Spring Boot application.properties :

\n\n
spring.application.name=my-web-app\nserver.port=8000\nspring.jpa.show-sql=true\nspring.h2.console.enabled=true\n
Run Code Online (Sandbox Code Playgroud)\n\n

Docker 图像输出:

\n\n
CK@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\n
Run Code Online (Sandbox Code Playgroud)\n\n

启动容器:

\n\n

请注意,我映射了Spring Bootserver.port application.properties映射到外部端口。

\n\n
docker …
Run Code Online (Sandbox Code Playgroud)

java windows tomcat docker spring-boot

2
推荐指数
1
解决办法
2347
查看次数

Spring Batch:单个作业的多个 JobExecutionListener 实例的执行顺序

给定一个为其配置了实例列表的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参考文档,但就我的研究而言,我找不到这个文档。

java listener spring-batch order-of-execution

1
推荐指数
1
解决办法
808
查看次数