• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Thread.currentthread method on multi cpu

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 218
VI Editor Ruby Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I believe it will be returning the Thread that your code is running on at the moment you call currentThread() method.
 
best scout
Posts: 1294
Scala IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
author
Posts: 23951
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
 
reply
    Bookmark Topic Watch Topic
  • New Topic