aspose file tools
The moose likes Threads and Synchronization and the fly likes Thread.currentthread method on multi cpu Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


JavaRanch » Java Forums » Java » Threads and Synchronization
Reply Bookmark "Thread.currentthread method on multi cpu" Watch "Thread.currentthread method on multi cpu" New topic
Author

Thread.currentthread method on multi cpu

tsrif tsal
Greenhorn

Joined: Apr 10, 2008
Posts: 1
on muliple cpu machine - surely there are > 1 currently running thread.
how does the method Thread.currentthread() work?
you would expect it to return a list of currently running threads.
Wirianto Djunaidi
Ranch Hand

Joined: Mar 20, 2001
Posts: 195
I believe it will be returning the Thread that your code is running on at the moment you call currentThread() method.
Marco Ehrentreich
best scout
Bartender

Joined: Mar 07, 2007
Posts: 1221

Tsrif, why do you think there should always be >1 threads running on a multiprocessor system? There are of course some background threads running in the JVM which you have on every system but I think you're talking about the threads running your own code. And there are only the threads you would have on a single processor system which means usually just the main thread your code is automatically running in.

So your applications don't necessarily run multi-threaded just because they are running on a multiprocessor system. The main difference is that a multiprocessor system has the ability to run multiple threads really in parallel - in contrast to a single processor system which has to use some scheduler mechanisms for parallelizing threads. And perhaps on a multiprocessor systems you'll see more errors regarding the visibility of shared data because of caching effects etc. if your code isn't really thread-safe.

Marco
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 16815
    
  19

how does the method Thread.currentthread() work?
you would expect it to return a list of currently running threads


Yes, it is true. In a multicore / multiprocessor system it is possible to have more than one currently running thread.

But that is not the purpose of the method. The purpose of the method is to return the Thread object that is running the current code that calls the method -- and the purpose of that is to write thread specific code.

Henry


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
 
I agree. Here's the link: http://zeroturnaround.com/jrebel - it saves me about five hours per week
 
subject: Thread.currentthread method on multi cpu
 
Similar Threads
Thread using Runnable Interface
About thread.sleep()
Wait method (multithreading) currentmethod
Regain Access to Running Thread without passing reference
Question on threads