File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Threads and Synchronization and the fly likes Multiprocessor question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Threads and Synchronization
Bookmark "Multiprocessor question" Watch "Multiprocessor question" New topic
Author

Multiprocessor question

Ravi Shankarappa
Ranch Hand

Joined: Jan 09, 2010
Posts: 55
Is there anything in particular to pay attention to code multithreaded Java apps in multiprocessor CPUs?
Jeff Verdegan
Bartender

Joined: Jan 03, 2004
Posts: 6109
    
    6

You mean as opposed to multihtreaded code running on a single CPU?

No.

It doesn't matter what kind of hardware your code runs on. When writing multithreaded code, you always have to take the same steps to ensure proper handling of shared data. One CPU or a thousand, it makes no difference.
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18102
    
  39

Jeff Verdegan wrote:You mean as opposed to multihtreaded code running on a single CPU?

No.

It doesn't matter what kind of hardware your code runs on. When writing multithreaded code, you always have to take the same steps to ensure proper handling of shared data. One CPU or a thousand, it makes no difference.



Having worked with JVMs running on hundreds of cores, I have to recommend that there is a difference (regarding testing) -- and if you intend to run your application in production with hundreds of cores, make sure that your test environment also has hundreds of cores.

It is amazing how easy race conditions show up when there are hundreds of cores, and never do, when there are only a handful. And I don't just mean your application, I mean commercial products, open-sourced libraries, etc. We had to work around many bugs (along with reporting them) with various libraries (and application servers) that have been in heavy use (and trusted) for years.

Henry
Jeff Verdegan
Bartender

Joined: Jan 03, 2004
Posts: 6109
    
    6

Henry Wong wrote:
Jeff Verdegan wrote:You mean as opposed to multihtreaded code running on a single CPU?

No.

It doesn't matter what kind of hardware your code runs on. When writing multithreaded code, you always have to take the same steps to ensure proper handling of shared data. One CPU or a thousand, it makes no difference.



Having worked with JVMs running on hundreds of cores, I have to recommend that there is a difference (regarding testing) -- and if you intend to run your application in production with hundreds of cores, make sure that your test environment also has hundreds of cores.

It is amazing how easy race conditions show up when there are hundreds of cores, and never do, when there are only a handful.


Absolutely true. And if you know how many cores you'll be running on, you can tailor your code to take optimal advantage of that.

My point was simply that the same race conditions that you'll more likely see on a hundred cores can happen on a single core, as far as the rules of the Java language and the JVM are concerned, so there's nothing additional that you have to take into account in order to write correct code.

Pat Farrell
Rancher

Joined: Aug 11, 2007
Posts: 4634
    
    5

Jeff Verdegan wrote: so there's nothing additional that you have to take into account in order to write correct code.


OK, I'll grant that.

But I also maintain that "writing correct code" using Java is far harder than most folk think when they start reading about the subject.
IMHO, Java's tools are the minimum you need, if you are as good as someone like @Henry, to do the job. But they do not approach making it easy to do.

Since it is hard to write correct code, its easy to write incorrect code. Its a lot easier to trigger the bad code, bad race conditions, etc. when you have lots of cores. Deciding what number defines "lots of cores" is an exercise to the reader.

These days, 6 core X86 processors cost $100. For $200, its easy to get 6 core processors that use hyper-threading techniques to act like 12 cores. I fully expect 16 core systems to be cheap and in production before this coming Christmas.

Jeff Verdegan
Bartender

Joined: Jan 03, 2004
Posts: 6109
    
    6

Pat Farrell wrote:
But I also maintain that "writing correct code" using Java is far harder than most folk think when they start reading about the subject.


No! The "21 days" book wouldn't lie to me!

But yeah, writing correct code is hard enough, but when you bring multithreading into the picture, it gets enormously more complex, and it's a lot harder to test.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Multiprocessor question
 
Similar Threads
Cause a thread to stop
Thread.currentthread method on multi cpu
Is Concurency dependent on CPU architecture?
Threading in Multiprocesser environment
SMT