Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

multithreading

 
praveen bhushan
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4181
21
IntelliJ IDE Java Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
praveen bhushan
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 87
Java Opera
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Rancher
Posts: 42967
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic