Last week, we had the author of TDD for a Shopping Website LiveProject. Friday at 11am Ranch time, Steven Solomon will be hosting a live TDD session just for us. See for the agenda and registration link
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

thread safe classes...

 
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
what is thread safe???
when a class is said to be thread safe???
 
Ranch Hand
Posts: 488
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thread safe means that a piece of code can only be accessed by one Thread at a time. This uses the synchronized keyword.

If a class is said to be "thread safe" it means that all the methods in that class are synchronized, or again, can only be accessed by one Thread at a time.

Search on multithreading and synchronization for more information.

EDIT: Remember that a class can not be defined as synchronized, just the methods in the class.
[ November 12, 2008: Message edited by: Brian Legg ]
 
author
Posts: 23919
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Thread safe means that a piece of code can only be accessed by one Thread at a time. This uses the synchronized keyword.



I am not sure if I agree with this... IMO, Thread Safe means that the class can be accessed by multiple threads, and it will still work as documented. It could be achieved by synchronization. It could be achieved by segmenting data. It could be achieved by optimistic locking. It could even be achieved by documenting that it will throw an exception condition, under certain situations.

Henry
 
Brian Legg
Ranch Hand
Posts: 488
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'll have to concede to the man who wrote the book on threads.
 
You know it is dark times when the trees riot. I think this tiny ad is their leader:
free, earth-friendly heat - a kickstarter for putting coin in your pocket while saving the earth
https://coderanch.com/t/751654/free-earth-friendly-heat-kickstarter
reply
    Bookmark Topic Watch Topic
  • New Topic