aspose file tools*
The moose likes Threads and Synchronization and the fly likes Get adavatage of multiple core hardware Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Threads and Synchronization
Bookmark "Get adavatage of multiple core hardware" Watch "Get adavatage of multiple core hardware" New topic
Author

Get adavatage of multiple core hardware

Costa Lamona
Greenhorn

Joined: Sep 17, 2006
Posts: 29
Hi

1) If I have a sever with 5 Processors, how to ensure that JVM will take advantages of these processors?

2) Does a multi-core hard ware need another arrangement?

Is implementing Runnable Thread is enough or there is something I should do.

Thanks
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18990
    
  40

All modern JVMs are implemented to have the OS deal with threading issues. All modern OSes (that I know of) are implemented to have different threads on different processors cores, if available.

So, as long as you are using current stuff, you really don't have to do much. The JVM should place different threads on different processors -- hence, it should "take advantage" of multiple processors.

Henry


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
Ajay Saxena
Ranch Hand

Joined: Nov 13, 2006
Posts: 154
All modern JVMs are implemented to have the OS deal with threading issues


To add to Henry's comment, pre-Java 1.2 used Green threads(User space threads),for enabling multi-threaded application development on platforms (OSes) that didn't have native support for multi-threading.

So if you are using Java 1.1,then probably the JVM needs to be instructed/configured someway to leverage multiprocessing capabilities of a multi-core machine.

However,I've no idea how user space threads could be scheduled on different processors bypassing the OS ( assuming the OS lacks thread support)

Henry,would you like to throw some light on that?

[ August 27, 2008: Message edited by: Ajay Saxena ]
[ August 27, 2008: Message edited by: Ajay Saxena ]
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18990
    
  40

Henry,would you like to throw some light on that?


It's quite simple. User level threads are not seen by the OS. Hence, as far as the OS is concerned, you have a single threaded application, no matter how many threads the Java application has.

In terms of timing, Java 1.1 / 1.2 was around 1996 or 1997. So, you are really going back a ways. IOWs, while I really like the history lesson, let's make sure that the OP deems it relevent to the question first.

Henry
Ajay Saxena
Ranch Hand

Joined: Nov 13, 2006
Posts: 154
It's quite simple. User level threads are not seen by the OS. Hence, as far as the OS is concerned, you have a single threaded application, no matter how many threads the Java application has.


So for multi-core machines running OSes lacking support for multithreading,concurrent programming would remain limited to multi-Processing only.
Chris Hurst
Ranch Hand

Joined: Oct 26, 2003
Posts: 418
    
    2

"All modern OSes (that I know of) are implemented to have different threads on different processors cores, if available."


Can't you have it either way with Solaris for instance ? i.e. specifically restrict to one core, though I can't claim to have played with it apparently there are advantages with each setup.

Its discussed here ...

http://mail-archives.apache.org/mod_mbox/lucene-java-user/200804.mbox/%3C480D1459.50908@teamware.com%3E


"Eagles may soar but weasels don't get sucked into jet engines" SCJP 1.6, SCWCD 1.4, SCJD 1.5,SCBCD 5
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18990
    
  40

Originally posted by Ajay Saxena:


So for multi-core machines running OSes lacking support for multithreading,concurrent programming would remain limited to multi-Processing only.


OSes that lack support for multithreading generally isn't capable of using multiple cores, so... no. This is, of course, a moot argument, unless you want to try it out by installing an old DOS instance somewhere.

Under the green threads model. Threading is handled by the green threads library. The user level library will timeslice the threads to use the one processor that it is capable of supporting. To the OS, it doesn't see the threading. It sees one thread running on one processor -- it just happens to be a scheduler and running on this one thread on the one processor.

Henry
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18990
    
  40

Originally posted by Chris Hurst:

Can't you have it either way with Solaris for instance ? i.e. specifically restrict to one core, though I can't claim to have played with it apparently there are advantages with each setup.


Yes. Certain old versions of Solaris supports both Kernal and User Level threads. But the argument still applies. The Kernal only sees the Kernal level threads -- it doesn't see the User level threads.

And this last part is still debateable. It can generally be argued that support of both kernal and user level threads is a *failed* experiment. Modern version of Solaris support Kernal level threads only as the default model. User level threads (LWPs) is only support for backward compatibility.

Henry
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Get adavatage of multiple core hardware