File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Java in General and the fly likes To Cay and Gary: Concurrency Utilities Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Make it so: Java DB Connections & Transactions this week in the JDBC forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "To Cay and Gary: Concurrency Utilities " Watch "To Cay and Gary: Concurrency Utilities " New topic

To Cay and Gary: Concurrency Utilities

Nicholas Cheung
Ranch Hand

Joined: Nov 07, 2003
Posts: 4982
Hi Cay and Gary,

What have this actually done and enhanced for us in a multi-threaded environment?


SCJP 1.2, OCP 9i DBA, SCWCD 1.3, SCJP 1.4 (SAI), SCJD 1.4, SCWCD 1.4 (Beta), ICED (IBM 287, IBM 484, IBM 486), SCMAD 1.0 (Beta), SCBCD 1.3, ICSD (IBM 288), ICDBA (IBM 700, IBM 701), SCDJWS, ICSD (IBM 348), OCP 10g DBA (Beta), SCJP 5.0 (Beta), SCJA 1.0 (Beta), MCP(70-270), SCBCD 5.0 (Beta), SCJP 6.0, SCEA for JEE5 (in progress)
Cay Horstmann
Ranch Hand

Joined: Nov 14, 2004
Posts: 137
The concurrency utilities are actually the most important part of the Tiger multithreading support. In a previous posting I had a three-part strategy to access shared data from multiple threads:

1) Avoid the problem by using a thread-safe collection
2) Use synchronization (synchronized keyword or Lock/Condition)
3) Use volatile

The concurrency utilities provide the support for the first option.

For example, it is often possible to implement an algorithm so that some worker thread put their work on a queue, and other threads take the work off that queue. That way, objects are handed off safely, and the only shared object is the queue itself.

java.util.concurrent gives you threadsafe implementations of queues, maps, arrays, and priority queues that are a lot more sophisticated than what you learned in college. For example, according to the javadoc, LinkedQueue "employs an efficient "wait-free" algorithm based on one described in Simple, Fast, and Practical Non-Blocking and Blocking Concurrent Queue Algorithms by Maged M. Michael and Michael L. Scott."

In addition, java.util.concurrent gives you implementations of a thread pool, so you don't have to reinvent that wheel. There are a few other goodies--see Core Java vol. 2 ch. 1.



Author of Java 8 for the Really Impatient
Alvin chew
Ranch Hand

Joined: Jan 08, 2004
Posts: 834
can someone kindly please explain what is thread safe means ? thank you !
Nicholas Cheung
Ranch Hand

Joined: Nov 07, 2003
Posts: 4982
what is thread safe means

Thread safe means, when an object is being invoked by more than 1 object at the same time, the state of that object will be consistent to the same caller object.

Nicholas Cheung
Ranch Hand

Joined: Nov 07, 2003
Posts: 4982
Hi Cay,

That is to say, Tiger has already provided a set of thread safe collections, or still, we need to do *something* to make sure the collection is thread safe?

I agree. Here's the link:
subject: To Cay and Gary: Concurrency Utilities
jQuery in Action, 3rd edition