• 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:
  • Devaka Cooray
  • Campbell Ritchie
  • Tim Cooke
  • Ron McLeod
  • Paul Clapham
Sheriffs:
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Saloon Keepers:
  • Tim Holloway
Bartenders:

do u know something about these Threads?

 
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Intelligent Ranchers!!
When I compiled the following program, the result really amazing, having new concept for me.
Try this program:
class A extends Thread{
public static void main(String args[])throws SecurityException{
System.out.println(Thread.activeCount());
Thread [] tarray = new Thread[5];
int x = Thread.enumerate(tarray);
System.out.println((tarray[0]).getName());
System.out.println((tarray[1]).getName());
System.out.println((tarray[2]).getName());
}
}
The output is:
3
main
SymcJIT-LazyCompilation-0
SymcJIT-LazyCompilation-PA
Is'nt it amazing? I never heard about the last two threads. At least I think one of them should be the low-priority thread for GC, but which one, I can't guess. And what is the purpose of these two threads if i'm wrong about one.
One thing is sure that every program has at least 3 threads on it's background.
Tell if i'm wrong and tell me about these threads.
Regards
Farhan
 
Sheriff
Posts: 5782
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I got a NullPointerException when I ran the program. ( JDK 1.3, Windows NT 4 )
Here's the output


D:\MyJava\MyProjects\JRanchQs>java NewThreads
1
main
Exception in thread "main" java.lang.NullPointerException
at NewThreads.main(NewThreads.java:10)


[This message has been edited by Ajith Kallambella (edited June 06, 2001).]
 
Ranch Hand
Posts: 234
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
farhan i also got the same output as u did
 
Ajith Kallambella
Sheriff
Posts: 5782
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Farhan and Sona, what OS are you running ?
 
Ranch Hand
Posts: 400
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I got exactly the same output as Ajith...
(JDK 1.3, windows'98)
 
Ranch Hand
Posts: 82
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I got the exactly output as Farhan did (compile and run).
(JDK 1.2.2_006, Windows NT workstation 4.0)
 
Ajith Kallambella
Sheriff
Posts: 5782
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This is a bug with Thread.activeCount() method.
According to the "JavaTM 2 Platform, Standard Edition, v 1.3 - API Specification":
- activeCount() returns the current number of ACTIVE threads in this thread's thread group;
- enumerate() copies into the specified array every ACTIVE thread in this thread's thread group and its subgroups, and returns the number of threads put into the array.
Problem 1: activeCount() returns MORE than the number of active threads, i.e. it returns the TOTAL number of ALL threads, including the threads that have not been started yet!
Problem 2: sometimes(?), activeCount() even returns a wrong value, i.e. a number EXCEEDING the total number of all threads!
For more details read the bug parade report - http://developer.java.sun.com/developer/bugParade/bugs/4412854.html and related bugs in that post. You will need a login id if you don't already have one. It is free!
------------------
Ajith Kallambella M.
Sun Certified Programmer for the Java�2 Platform.
IBM Certified Developer - XML and Related Technologies, V1.
 
Farhan Tariq
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello!!
Ajith said it right that 1.3 version give us null pointer exception. According to 1.2.2 the activeCount for simple program tell us three threads working behind, but in 1.3 only one. Plz remember that the certification is for 1.2.2 not for 1.3 yet.
Another point is that when we execute our program one thread is sure to be run which is main but i think we forget the one that is GC (at least I read that GC is a low priority thread which works at behind any program). So we have two threads now. Last one i think (guess) that it work for reusing the memory occupied by the objects which are no longer be referenced (this report "no longer be referenced" is given by the GC thread).
In my opinion three threads exist even in 1.3 but we can't see them for some what security point of view in think. Tell me if i'm wrong.
Regards
Farhan
 
This tiny ad is wafer thin:
Paul Wheaton's 16th Kickstarter: Gardening playing cards for gardeners and homesteaders
https://coderanch.com/t/889615/Paul-Wheaton-Kickstarter-Gardening-playing
reply
    Bookmark Topic Watch Topic
  • New Topic