Last week, we had the author of TDD for a Shopping Website LiveProject. Friday at 11am Ranch time, Steven Solomon will be hosting a live TDD session just for us. See for the agenda and registration link
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

multithreading

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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....
 
Bartender
Posts: 4179
22
IntelliJ IDE Python Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 87
Opera Java
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Rancher
Posts: 43027
76
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
No matter. Try again. Fail again. Fail better. This time, do it with this tiny ad:
Free, earth friendly heat - from the CodeRanch trailboss
https://www.kickstarter.com/projects/paulwheaton/free-heat
reply
    Bookmark Topic Watch Topic
  • New Topic