Skip to content

"targetWriter" is a method parameter, and should not be used for synchronization. #5884

@MinaQin

Description

@MinaQin

Code Path:server/src/main/java/org/apache/iotdb/db/engine/compaction/writer/AbstractCompactionWriter.java
image
Synchronizing on a class field synchronizes not on the field itself, but on the object assigned to it. So synchronizing on a non-final field makes it possible for the field’s value to change while a thread is in a block synchronized on the old value. That would allow a second thread, synchronized on the new value, to enter the block at the same time.

The story is very similar for synchronizing on parameters; two different threads running the method in parallel could pass two different object instances in to the method as parameters, completely undermining the synchronization.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions