这是indexloc提供的服务,不要输入任何密码
Skip to content

[ISSUE] Feedback inapprotiate examples #16743

@XinAnzzZ

Description

@XinAnzzZ

Article and Module Links
https://www.baeldung.com/java-threadlocal

core-java-modules/core-java-concurrency-advanced/src/test/java/com/baeldung/threadlocal/ThreadLocalIntegrationTest.java

Describe the Issue
In the 4th chapter of this article, I believe there is a mistake in your demonstration of how to use ThreadLocal, the example does not effectively illustrate the true functionality of ThreadLocal.

The main functionality of ThreadLocal is for thread isolate, actully, you have created two objects, thus they have own threadlocal
object, i believe that there are no share

The purpose of ThreadLocal is to provide thread isolation. However, the code example you provided actually creates two separate ThreadLocal objects, with each thread having its own independent ThreadLocal object. I believe that this does not demonstrate thread sharing and, as a result, fails to illustrate the effect of thread isolation.

Metadata

Metadata

Assignees

No one assigned

    Labels

    on-jiratriagedIssues reviewed by a dev and considered valid. Will be added in Jira.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions