Results 1 to 4 of 4
  1. #1
    Ashish is offline Member
    Join Date
    Jul 2007
    Posts
    4
    Rep Power
    0

    Default When to use ThreadLocal

    When should i use ThreadLocal? What would I acheive from that? Is there any scenerios where I should use ThreadLocal?

  2. #2
    oregon is offline Member
    Join Date
    Jul 2007
    Posts
    41
    Rep Power
    0

    Default

    You usually use a ThreadLocal when you have several threads that needs to have its own local data.

  3. #3
    ingle.anil is offline Member
    Join Date
    Dec 2007
    Posts
    3
    Rep Power
    0

    Default Global variable kind

    let suppose you program is system and there may be may subsystems, how can you pass message between these subsystems ..lots of way in which you can do this ..one way is global variable.
    think as subsystems is thread and that thread calls/calls lots of new threads ( sub subsystems ) in this sort of scenario you create ThreadLocal variable in parent class and use that in sub sub systems.:)

  4. #4
    danielstoner's Avatar
    danielstoner is offline Senior Member
    Join Date
    Apr 2008
    Location
    Canada
    Posts
    191
    Rep Power
    7

    Default

    Sorry ingle.anil but that doesn't make sense. ThreadLocal is not global variable at all. It is storage for a specificthread. Another thread cannot access that data. ThreadLocal can help you write code that is concurrency aware and needs to associate data with each execution thread. Managing DB statements can be a good example.
    Daniel @ [www.littletutorials.com]
    Language is froth on the surface of thought

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •