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 multithreading Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Threads and Synchronization
Bookmark "multithreading" Watch "multithreading" New topic
Author

multithreading

praveen bhushan
Greenhorn

Joined: Feb 23, 2011
Posts: 2
As we know that quad core processor has four processors, so keeping that in mind I need a program in java wherein we can use the concept of running multiple threads simultaneously in four different processor...In this case four different threads in four different processor....I somewhere read that to implement this we need to utilise 100% resource of each processor...basically its a kind of multi tasking.....please help me out as it is necessary for my project...any kind of help is most welcome....
Steve Luke
Bartender

Joined: Jan 28, 2003
Posts: 4167
    
  21

Hi Praveen,

If you use multiple threads in current Java implementations, then if your computer has 4 cores those threads will be distributed to where there is extra processor cycles. So if you have four tasks then they can get distributed to all 4 cores. That doesn't necessarily mean they will get spread out to all four cores, just that they could be if needed to be.

So I have a question: Do you absolutely need to use 1 thread per core? Why? Why not just take the cycles as they come available from any of the cores?

Making sure your app takes up 100% of a cores cycles is not as easy as you might thing - and it is never a good thing, especially not to do it intentionally just to spread your threads out to multiple cores.


Steve
praveen bhushan
Greenhorn

Joined: Feb 23, 2011
Posts: 2
Steve Luke wrote:Hi Praveen,

If you use multiple threads in current Java implementations, then if your computer has 4 cores those threads will be distributed to where there is extra processor cycles. So if you have four tasks then they can get distributed to all 4 cores. That doesn't necessarily mean they will get spread out to all four cores, just that they could be if needed to be.

So I have a question: Do you absolutely need to use 1 thread per core? Why? Why not just take the cycles as they come available from any of the cores?

Making sure your app takes up 100% of a cores cycles is not as easy as you might thing - and it is never a good thing, especially not to do it intentionally just to spread your threads out to multiple cores.



Hii Steve, thanks for your suggestion . Actually my professor is telling me to do it. Is it possible to run one thread per processor. I think its a tedious job to do and moreover its risky I guess.
prem pillai
Ranch Hand

Joined: Nov 02, 2007
Posts: 87

I don't think there is any way to control CPU allocation for threads.

I would think about running 4 different processes instead of threads if that is an unavoidable requirement; But these things are very much depdendent on what actually you want to do with those threads/processes.
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41107
    
  45
It's also quite likely that at least one of the cores (or processors) would not be available for the JVM because the OS uses it to run OS processes, or other application processes. Even if all cores are available to the JVM, the JVM might use one of them to run some of its internal threads instead of user threads.


Ping & DNS - my free Android networking tools app
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: multithreading
 
Similar Threads
Threads in a single processor
Payment Gateway in java
XSLT Processor
Regarding threads
New threading architecture leads to unexpected results