• 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

Number of threads DOUBT

 
Ranch Hand
Posts: 111
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I run the code on both Windows and Linux paltform


public class TestClass
{
public static void main(String[] args)
{

System.out.println(Thread.activeCount());
}
}



Sometimes the output is coming 1 and sometimes 2.Is the behaviour of activeCount() method is platform dependent?

 
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
When I run this inside the BlueJ IDE on windows I get 4 (four) threads.
Exercise for student: find and print information about the threads which are active
 
Barry Gaunt
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
For Java 5.0 you can run this:


Output in BlueJ:

[ November 18, 2004: Message edited by: Barry Gaunt ]
 
Ranch Hand
Posts: 298
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am running the code in EDITPLUS, and I am always getting '1' as answer. Because only 1 main thread is running then answer should alwasy be 1.

But when you are running in an IDE like BlueJ or Jcreator, you will get more than 1 thread. The reason behind all this is that, these IDE are completely based on java and when you run a single instance of these IDE, it starts JVM and do some process before you start your own program.

This is why you get more than 1 as answer.

Kaps
 
Anil Kumar Saha
Ranch Hand
Posts: 111
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Barry and Kapil for clearing my doubts.
 
rubbery bacon. rubbery tiny ad:
free, earth-friendly heat - a kickstarter for putting coin in your pocket while saving the earth
https://coderanch.com/t/751654/free-earth-friendly-heat-kickstarter
reply
    Bookmark Topic Watch Topic
  • New Topic