Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Register Tags Active Topics RSS Search Mark Forums Read SiteMap

Tags: , , , ,

Sponsored Links



Thread- Safe Classes

Software Development


Reply
 
Thread Tools Search this Thread
  #1  
Old 09-02-2010
Member
 
Join Date: Dec 2009
Posts: 192
Thread- Safe Classes

Hello,
Does someone could tell me a place where you can find a list more or less complete collections of Java classes that are thread-safe and which are not? Thank you in advance. I am new to this concept and do not want to take any risk, so please any help in this will be highly appreciated.
Reply With Quote
  #2  
Old 09-02-2010
Member
 
Join Date: Nov 2009
Posts: 447
Re: Thread- Safe Classes

Hello,
Here are few points on this
- The classes of the old APIs are thread-safe (Hashtable, Vector and Stack) But should not be used in general.
- Unless I am mistaken, the classes of the "new" Collections API (all other collections java.util) Are not thread-safe, but it is possible to obtain a thread-safe version via methods Collections.synchronizedXXXX ().
- Finally collections package java.util.concurrent are logical thread-safe.
Reply With Quote
  #3  
Old 09-02-2010
Member
 
Join Date: Dec 2009
Posts: 213
Re: Thread- Safe Classes

Hello,
Even I am trying a similar kind of a code, but I can not get the logic. It means that the only data structures that can be used without the sync itself is the object returned by Collections synchronizedXXX () and objects in java.util.concurrent, according to the practice whereby all application must be considered as a multithreaded application? I am not conferable with this.
Reply With Quote
  #4  
Old 09-02-2010
Member
 
Join Date: Nov 2009
Posts: 333
Re: Thread- Safe Classes

Hello,
Not exactly, your application is heavily threaded all data will be handled by multiple threads challenge. Thus, it has now to determine the data / process need to be thread safe. I do not think this will make you any problem. So, you can carry on with this code and I think this is safe for you program and if you think this is not safe then you can use the multithreading in which is provided by java.

Last edited by Linux-Us : 09-02-2010 at 11:45 PM.
Reply With Quote
  #5  
Old 09-02-2010
Member
 
Join Date: Dec 2009
Posts: 178
Re: Thread- Safe Classes

Hello,
I can integrate this conversation by asking a small question.
In the case where a collection should be synchronized, which solution to choose?
1 / Vector and etc.
2 / Standard collection (LinkedList and other) synchronized by us.
3 / classes package java.util.concurrent
Thanks in advance for your reply.
Reply With Quote
  #6  
Old 09-02-2010
Member
 
Join Date: Nov 2009
Posts: 583
Re: Thread- Safe Classes

Hello,
Vector, Stack and Hashtable you can forget them. these classes should be used. If necessary collections thread-safe, it generally uses synchronized versions of standard collections (retrieved via methods synchronisedXXX () class Collection) The collections available in this package java.util.concurrent used primarily for specific needs:

- The BlockingQueue is a queue (a queue thus FIFO) which hangs when trying to add or remove an element as the space available is not sufficient (model producer / consumer).

- The ConcurrentMap Map is a thread-safe which is distinguished by the fact that it can be supervised by several bolts of exclusion, ie it can allow multiple simultaneous entries, unlike the conventional synchronized Map n ' only one exclusion lock (only 1 write simultaneously possible as a result).
Reply With Quote
Reply

  TechArena Community > Software > Software Development


Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "Thread- Safe Classes"
Thread Thread Starter Forum Replies Last Post
Synchronize a producer thread and a consumer thread in C# Ayuka Software Development 6 10-11-2010 04:04 AM
IE9 Beta and Norton Safe Web and Identity Safe Phillips Networking & Security 6 24-09-2010 07:19 AM
Safe Eyes Mobile - The First Kid-Safe Browser for Apple iPhone monsitj Portable Devices 2 07-02-2009 09:22 AM
computer loops at safe mode,safe w/command prompt, etc. screen (XP Pro) caver Windows XP Support 2 06-01-2008 12:09 PM


All times are GMT +5.5. The time now is 05:18 AM.