Results 1 to 5 of 5
  1. #1
    Join Date
    Jul 2010
    Posts
    12
    Rep Power
    0

    Default How to synchronize an object ???

    Hello all,

    I know that we can synchronize a method or a block of code in a java class . But what is this synchronized classes ( HashTable) and how to synchronize a nonsynchronized objects to synchronized one ???
    Anantha Nag . KUNDANALA
    ph : 9052012019 , 8143195317

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

  3. #3
    Join Date
    Jul 2010
    Posts
    12
    Rep Power
    0

    Default

    Dear Fubarable ,
    Here is my detailed question .

    In collections , we have two classes ArrayList and Vector .

    ArrayList is a non synchronized class and Vector is a synchronized class . Am I right ?

    So, what is this synchronized class ???

    And I know how to synchronize a method . But I don't know how to synchronize a class similar to that of Vector .

    hope you will get me clearly .
    Anantha Nag . KUNDANALA
    ph : 9052012019 , 8143195317

  4. #4
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    4,041
    Rep Power
    10

    Default

    There is no such thing as a "synchronized Object". Vector contains some synchronized methods and/or code pieces. That's it. If you want to "synchronize a class", just make sure it is thread safe.

    Although, to be fair to the OP, the Vector API does say this: Unlike the new collection implementations, Vector is synchronized.
    How to Ask Questions the Smart Way
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  5. #5
    Join Date
    Jul 2010
    Posts
    12
    Rep Power
    0

    Default

    So , making a class ' Thread Safe ' is nothing but ' Synchronizing a class ' ???

    I know how to prepare a class thread safe . Thanks a ton .

    uffffff...... OK ... Thank you Kevin and Fubarable.
    Anantha Nag . KUNDANALA
    ph : 9052012019 , 8143195317

Similar Threads

  1. Replies: 1
    Last Post: 02-08-2010, 02:33 PM
  2. how to synchronize a thread
    By sumanandjesus in forum Advanced Java
    Replies: 4
    Last Post: 03-14-2009, 11:26 AM
  3. Replies: 0
    Last Post: 04-09-2008, 07:39 PM
  4. How to synchronize threads on an object
    By Java Tip in forum java.lang
    Replies: 0
    Last Post: 04-09-2008, 07:39 PM
  5. Can't synchronize multiple JPanels in a JFrame
    By vassil_zorev in forum AWT / Swing
    Replies: 0
    Last Post: 12-30-2007, 05:22 PM

Posting Permissions

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