Skip to content

volatile 代码示例问题 #2

@liyiopener

Description

@liyiopener

file:
src/main/java/com/example/concurrency/features/volatilecase/VolatileExample.java
line: 43
new Thread(aVolatile::stopThread).start();

该示例存在歧义,aVolatile::stopThread 会自动创建匿名 Runable 实现类对象,但这个对象与示例中 Volatile 实现类并不相等,
目的只是通过调用 stopThread 修改 volatile 变量而中止线程,43 行这种写法有很大的误导性

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions