aspose file tools*
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes Java 1.6 and concurrency Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "Java 1.6 and concurrency" Watch "Java 1.6 and concurrency" New topic
Author

Java 1.6 and concurrency

William Smith II
Ranch Hand

Joined: Apr 26, 2007
Posts: 39
A couple of questions:

(1) If I use the latest JDK 1.6 u3, do I have to use the concurrency package? I am using standard wait/notify and synchronized blocks. I just wanted to use the most recent JDK.

(2) If I use JDK 1.6, will I lose marks if I don't use some of the new constructs? For example, what if I pass back String[] from a method instead of ArrayList<String>?

(3) This doesn't have to do with 1.6. I use a HashSet for my locking manager. So long as I use syncronized blocks on the objects, what's the difference between these two statements. I've read the API, but I'm not 100% I understand. I think I'm okay so long as I use syncronized blocks on the HashSet object (using hs1).
HashSet hs1 = new HashSet();
HashSet hs2 = Collections.synchronizedSet(new HashSet());
R van Vliet
Ranch Hand

Joined: Nov 10, 2007
Posts: 144
Hi William,

My answers below

Originally posted by William Smith II:
A couple of questions:
(1) If I use the latest JDK 1.6 u3, do I have to use the concurrency package? I am using standard wait/notify and synchronized blocks. I just wanted to use the most recent JDK.


No, synchronized blocks are not deprecated or outdated. The java.util.conurrency package simply offers additional functionality rather than replace the old way of adding thread synchronization. Whether or not you prefer using Lock over synchronized blocks is more a matter of style than anything else (provided you dont need the additional functionality offered by the Lock classes).

Originally posted by William Smith II:

(2) If I use JDK 1.6, will I lose marks if I don't use some of the new constructs? For example, what if I pass back String[] from a method instead of ArrayList<String>?


I can imagine you may lose marks for choosing a sub optimal way of returning a list of values. But keep in mind that your two options aren't directly related to moving to 1.6 (or more accurately, 1.5 in the case of generics). The change would be from List to List<String>. If you're worried about what would be the best approach you can always start a new thread with that specific question as a topic.

Originally posted by William Smith II:

(3) This doesn't have to do with 1.6. I use a HashSet for my locking manager. So long as I use syncronized blocks on the objects, what's the difference between these two statements. I've read the API, but I'm not 100% I understand. I think I'm okay so long as I use syncronized blocks on the HashSet object (using hs1).
HashSet hs1 = new HashSet();
HashSet hs2 = Collections.synchronizedSet(new HashSet());


Creating a synchronized set means the individual methods of the set become atomic. This is not the same as synchronized blocks, for example :



Even though your collection is synchronized, another thread could still modify the collection and thus influence the result of the size() method between these two lines of code. The result then is that perhaps the wrong value is added to the collection.

This is a relatively useless example by the way
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Java 1.6 and concurrency