• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

Thread behaviour in multiple CPU/Processor Environment

 
Ranch Hand
Posts: 82
Eclipse IDE Spring Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

When a jvm invokes multiple threads in multiple cpu's environment, do threads share CPU's or they run only in the CPU where JVM is running

Also,Is there any way to see/print in which JVM a java thread is running,?

Thanks,
Don...
 
Marshal
Posts: 25682
69
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Don Redd wrote:the CPU where JVM is running



Are you sure this is a meaningful concept?
 
Don Redd
Ranch Hand
Posts: 82
Eclipse IDE Spring Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Not sure though, but the Actual question comes to my mind from below scenario;

Lets say, I have a System with 64 processors(CPU's), I started an instance of JETTY web sever, where my web app is running, My web app creates Java Threads internally and I want to know whether the threads use more than one processor to run or not to achieve real parallelism. ( As,am seeing not a great improvement in terms of TIME with increase in thread count, I GUESS, its using single processor/CPU only).


 
Bartender
Posts: 1558
5
Eclipse IDE Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Don Redd wrote:Not sure though, but the Actual question comes to my mind from below scenario;

Lets say, I have a System with 64 processors(CPU's), I started an instance of JETTY web sever, where my web app is running, My web app creates Java Threads internally and I want to know whether the threads use more than one processor to run or not to achieve real parallelism. ( As,am seeing not a great improvement in terms of TIME with increase in thread count, I GUESS, its using single processor/CPU only).



Well, in that case, technically speaking, its JVM's call about how to allocate threads - it can be one thread per CPU, or two threads per CPU, or 5 threads on one CPU, and 2 threads on another, or any other combination.

Now, distributing threads evenly over CPU is one thing, and witnessing significant improvement in application due to multiple threads is another thing. Its not always linear - like 1 thread does an operation in 1 second, hence 1000 threads would finish it in 1 millisecond.
There are other factors like how is speed-bottleneck (e.g. if all thread starts doing disk I/O, then even 64 threads will make the operation miserably slow than a single thread operation), how is result-merging time (e.g. is it really worth to divide a task in 100 small task, executing those separately, and then merging the result?) and so on.

However, even beyond everything, if you want to guarantee the true parallelism, I would recommend to take a look at fork-join framework introduced in JDK 7. There is a facility to allocate separate thread on separate CPU.

I hope this helps.
 
Don Redd
Ranch Hand
Posts: 82
Eclipse IDE Spring Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

This is helpful

Thanks Anayonkar,
 
Paul Clapham
Marshal
Posts: 25682
69
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I would suggest that a web application isn't a good way to test the performance of thread allocation unless you can get it heavily loaded, by sending it a heavy volume of requests. Otherwise the response time is going to be dominated by network transmission time, and any gain from different thread allocation behaviour is going to be far too small to notice.
 
World domination requires a hollowed out volcano with good submarine access. Tiny ads are optional.
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic