• Post Reply Bookmark Topic Watch Topic
  • New Topic

Threads:General Question

 
Christopher Arthur
Ranch Hand
Posts: 149
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here's a little discussion question about threads, java and recent computer development.

As we know, java runs in a virtual machine, so we don't need to know much about the hardware to make our programs. If we do need to know about the hardware, we usually query some special class that reports on the machine.

Java also uses threads extensively, and to understand their use is necessary for many programming efforts. We have to think about synchronization, e.g., what happens when thread A calls method M while thread B is already calling M.

Java aside for a moment, recent hardware developments are making multiple- core processors more and more available. The concept of threads in this case is similar to how it is in java, except the threads are no longer on a time-sharing plan, but instead they are running concurrently.

My point is that java seems to be a natural choice for working with multi-core processors, if it weren't for the layer of abstraction that the virtual machine creates.

I guess, what I'm wondering is what would be the best way to use java in these circumstances, and what development has been done? Would it be better to use one virtual machine per core and communicate via RMI or would there be a special release of java that could select which core on a per-thread basis?

I'm asking because I don't really know much about programming multiple cores, but I suspect that this is the way of the future.

Chris Arthur
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24213
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Christopher,

With modern JVMs, it's up to the OS to make use of the multiple cores. Java creates OS-level threads, and leaves it to the OS to schedule them. If the OS knows how to schedule two threads to run at once (and modern OSs certainly do) then the Java threads will run concurrently. So no special JVM is needed -- it's already working. Simple as that!

P.S. I've used dual-processor desktop machines for years, and Java has always been great about using multiple distinct processors when appropriate. We write some fairly compute-intensive software, and sometimes deliberately insert parallel sections to take advantage of this.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!