views:

168

answers:

7

OK I am not only new to concurrency in java but am also fairly new to java programming. I tried understanding concurrency from The java tutorials, tried reading Concurrency in practice but it seemed too advance, so tried reading from couple of other books: SCJP A comprehensive, The java programming language 4th edition.
Its as if there are things which just don't add up or make sense, I am not able to get the why's and how's and form the correct pattern of conceptual understanding. I apologize for describing this exercise in futility. But can someone please recommend good reading materials and/or ways to learn concurrency in java.

+2  A: 

My favorite learning Java Book which has a great chapter on concurrency is:

Sun Certified Programmer & Developer for Java 2 Study Guide (Exam 310-035 & 310-027)

alt text

Eric W
A: 

I checked this book out on amazon. Isn't this book too old i want to learn things in tearms of java 6

msk
The fundamentals of Java concurrency have not changed...once you understand those fundamentals you can then move on to more advanced topics and concurrency additions to Java 1.5.
Eric W
Please register your user account or stick to the same webbrowser without deleting cookies. You've now two user accounts. You can't edit/manage posts of the other account.
BalusC
Yeah I appreciate and understand that basics should be learnt first, which is what I am trying to do, that is learn basics of concurrency in core java and thats where I need guidance. I tried several books but it dint work.
msk
+5  A: 

but am also fairly new to java programming

Leave the concurrency book aside for a few months and go ahead with reading a basic Java/SCJP book and practicing basic Java a lot. Create so now and then a Thread or Runnable as per the book's instructions. Play around with it for some months until you get a good grasp on it. Then continue with the concurrency book.

Learn walking before running, else you're crawling instead of running.

BalusC
I have to agree with walking before running, but once you have read books on the basics of java the next book you read should be "Effective Java" by Josh Bloch. After all that, if you still don't get it, try simple queues and worker examples with synchronize.
Mondain
"A few months" is honestly said very optimistic as well. But if you have the motivation...
BalusC
Core Java by Horstmann and Cornell is also good and has coverage j.u.concurrent at the very end
Gene T
+3  A: 

It's a difficult subject, nobody has full grasp of it, not even those who designed it.

Many people understand only a subset of it. If you only know a few tricks/patterns that you can use in your programs with confidence, that's good enough. From there you accumulate more and more.

A novice may only know that he can add 'synchronized' keyword to methods. Amazingly that solved a lot of problems and performs just fine, even if he has no idea what he is doing.

irreputable
+3  A: 

This sounds like you will soon be tested (class? certification?) "on Java concurrency". You have not experienced the cycle of running into a problem naturally, thinking about how to solve it, and turning to concurrency for a solution. If this is the case...

(1) Don't blame your brain. Rather, take a step back and start thinking about problems that interest you. Write them down. Internet applications are a good place to start. For example-- writing some sort of Internet server that can handle multiple connections from different users, like a game server. Or, a stock trading program that has to handle your robot's orders at the same time as processing information from the broker.

(2) Think concurrency. Now that you have a problem that interests you, and thinking of concurrency simply as multi-tasking, draw a diagram of actors/programs with arrows representing how they need to communicate with each other. Sketch out a dummy-skeleton code. You're not actually going to write a game server; but you can make a simple skeleton class library with simple, empty member functions like connectToGame(){}

(3) Now you're ready. Run a hello-world thread example or two. Flip through your books or browse the Javadocs and see the different concurrent structures that are available. Think about which ones you might apply to your problem. Don't worry about making the "right choice". You will soon find out if you've got something that works.

(4) Embrace trial and error. There is another word for it: learning!

Now, after you get some experience doing this, you'll be able to pick up a Java concurrency book and read about someone else's problem.

Hang in there and don't give up.

Pete
A: 

I feel like I understand concurrency backward and forward. Recently, I grabbed a book off the shelf in our office and found it was VERY good. Not just at concurrency, it gives great coverage of Java as a whole.

Introduction to Java Programming, Eighth Edition: Comprehensive Version, Y. Daniel Liang

However, most of my understanding came from experience working with code, tackling problems, and trying examples. I never truly understood threading until I did it.

Concurrency is complex and most people won't get it just from reading. Look through the API and write some test programs to try things out. Whatever book you choose, try to not just read the code, write it out and run it. After a day or two, working with it, you'll have it mostly figured out.

gmale
A: 

To add my two cents worth: concentrate on learning the concepts of concurrency first, rather than the machanics of actually using it in any particular language. If you get bogged down in language constructs it'll be all that much harder to get a high-level understanding of the subject.

To this end I would recommend How to Write Parallel Programs by Carriero & Gelernter (free & legal PDF download). It strikes a good balance between describing the concepts and providing concrete code examples, and doesn't get bogged down in theory. It's actually very readable and entertaining (or maybe that might be just me).

alatkins