This week's book giveaway is in the Kotlin forum.
We're giving away four copies of Kotlin for Android App Development and have Peter Sommerhoff on-line!
See this thread for details.
Win a copy of Kotlin for Android App Development this week in the Kotlin forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Devaka Cooray
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Junilu Lacar
  • Paul Clapham
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • salvin francis
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Frits Walraven
  • Ganesh Patekar

Java 1.6 and concurrency  RSS feed

 
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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());
 
Ranch Hand
Posts: 144
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
All of the world's problems can be solved in a garden - Geoff Lawton. Tiny ad:
RavenDB is an Open Source NoSQL Database that’s fully transactional (ACID) across your database
https://coderanch.com/t/704633/RavenDB-Open-Source-NoSQL-Database
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!