aspose file tools*
The moose likes Threads and Synchronization and the fly likes Threading in multiple CPUs Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Threads and Synchronization
Bookmark "Threading in multiple CPUs" Watch "Threading in multiple CPUs" New topic
Author

Threading in multiple CPUs

Naresh Chaurasia
Ranch Hand

Joined: May 18, 2005
Posts: 356
In multi CPU environment how does threading work, and how does the allocation of threads/process take place across different CPUs


SCJP 1.4, SCWCD1.4, OCA(1Z0-007)
Chan Ag
Bartender

Joined: Sep 06, 2012
Posts: 1028
    
  15
how does threading work


I don't get your question. What do you mean by threading? Could you provide some more details?

how does the allocation of threads/process take place across different CPUs

It's an implementation detail of the OS and the scheduler in question. Why do you need to know this? Also if at all you need to know this, you can do a complex testing on the system in question and after many days ( if not months ) of testing, you might get an idea. And then it may change as well. I hope you know that a process and a thread are two different things?


Chan.
Naresh Chaurasia
Ranch Hand

Joined: May 18, 2005
Posts: 356
Chan thanks for quick and blunt answer. I should have put some more details in question, which i initially though would be obvious.

Let us say we have process p1 and p2. Each process can spawn threads t1....tn. Let us also assume i am working 2 processor environment with all other conditions(single & double processor) being same.

Let us say p1 is running on processor1 and p2 is running on processor2. p1 spawns threads t1,t2 and p2 spawn threads p3,p4.

question: When p1 spawns threads the does it run on a specific processor or can it switch the processors. I understand that it will depend on the environment(OS), but theoretically how does it work.

If i have to use concepts like synchronization, wait , sleep, join, notify etc. do i need to worry about the numbers of processors, or all the details are abstracted from user, and OS takes care of the stuff.
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18656
    
    8

Naresh Chaurasia wrote:If i have to use concepts like synchronization, wait , sleep, join, notify etc. do i need to worry about the numbers of processors, or all the details are abstracted from user, and OS takes care of the stuff.


You'll notice that the Thread class in Java doesn't have any methods which refer to processors, multiple or otherwise, in any way. Which means that how the JVM and the Thread class and the operating system will deal with allocating threads to processors is completely hidden from you.

And if you look farther I expect you'll see that the tutorials about Thread don't mention anything about that issue either. Another hint that it's none of your business.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Threading in multiple CPUs