Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

Posted on 2011-09-07
3
Medium Priority
?
276 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 10

Expert Comment

by:gordon_vt02
ID: 36504615
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 2000 total points
ID: 36504671
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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.
Suggested Courses

916 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