• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Multiprocessor question

 
Ravi Shankarappa
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is there anything in particular to pay attention to code multithreaded Java apps in multiprocessor CPUs?
 
Jeff Verdegan
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Marshal
Pie
Posts: 21016
78
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 6109
6
Android IntelliJ IDE Java
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4678
7
Linux Mac OS X VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 6109
6
Android IntelliJ IDE Java
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic