Solved

Use of Java.Util.Concurrent in multi-core server

Posted on 2011-09-07
3
264 Views
Last Modified: 2012-05-12
Hi:

What are things you have to take care of during multi-threaded programming using java.util.concurrent (java.util.concurrent package for Java 7) on multi core server.

Please let me know any thread safety issue's due in use of this package on multi-core or multi processor server.
 
Best Regards,

-Sunnybrad
0
Comment
Question by:sunnybrad
  • 2
3 Comments
 
LVL 47

Expert Comment

by:for_yan
Comment Utility
0
 
LVL 10

Expert Comment

by:gordon_vt02
Comment Utility
Take a look at the book Java Concurrency in Practice by Brian Goetz.  It's a great reference for concurrent programming and explains a lot of methods for making objects thread-safe.

http://jcip.net/
0
 
LVL 10

Accepted Solution

by:
gordon_vt02 earned 500 total points
Comment Utility
A quick summary of things to watch out for:

You need to make sure that any objects you are sharing among multiple threads are thread-safe.  The easiest way to do this is to make them immutable.  If the state of the object can't change, there are no issues sharing it among multiple threads.

If shared objects must be changed by one or more threads, you have several options:
- Use the built-in synchronized keyword on the accessor and mutator methods for the shared state
- Create a private final Object in your class that is used to lock only the code blocks that mutate the object.  (synchronized (lockObject) { // mutation code })
- Use the java.util.concurrent.AtomicXxx classes to provide atomic operations for ints, booleans, and other common types.
- Use the concurrency uttilities (Locks, Mutexes, etc.) in java.util.concurrent to handle explicit locking/unlocking of critical sections of your code.

There are other options as well, such as the volatile keyword, but I'd recommend reading one of the references out there -- JCIP being a great one -- for all the details and potential pitfalls.
0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
count8 challlenge 13 84
wordappend challenge 8 83
Modeling a class in java 5 31
What is the latest versions eclipse neon 2 116
Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now