Results 1 to 6 of 6

Thread: Thread- Safe Classes

  1. #1
    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.

  2. #2
    Join Date
    Nov 2009
    Posts
    446

    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.

  3. #3
    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.

  4. #4
    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.

  5. #5
    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.

  6. #6
    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).

Similar Threads

  1. Synchronize a producer thread and a consumer thread in C#
    By Ayuka in forum Software Development
    Replies: 6
    Last Post: 10-11-2010, 04:04 AM
  2. IE9 Beta and Norton Safe Web and Identity Safe
    By Phillips in forum Networking & Security
    Replies: 6
    Last Post: 24-09-2010, 06:19 AM
  3. Replies: 2
    Last Post: 07-02-2009, 09:22 AM
  4. Replies: 2
    Last Post: 06-01-2008, 12:09 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,713,249,789.41970 seconds with 17 queries