do u know something about these Threads?
posted 24 years ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
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
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
posted 24 years ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
I got a NullPointerException when I ran the program. ( JDK 1.3, Windows NT 4 )
Here's the output
[This message has been edited by Ajith Kallambella (edited June 06, 2001).]
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).]
Open Group Certified Distinguished IT Architect. Open Group Certified Master IT Architect. Sun Certified Architect (SCEA).
posted 24 years ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
farhan i also got the same output as u did
sona<br />SCJP
Ajith Kallambella
Sheriff
Posts: 5782
posted 24 years ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
Farhan and Sona, what OS are you running ?
Open Group Certified Distinguished IT Architect. Open Group Certified Master IT Architect. Sun Certified Architect (SCEA).
posted 24 years ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
I got exactly the same output as Ajith...
(JDK 1.3, windows'98)
(JDK 1.3, windows'98)
posted 24 years ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
I got the exactly output as Farhan did (compile and run).
(JDK 1.2.2_006, Windows NT workstation 4.0)
(JDK 1.2.2_006, Windows NT workstation 4.0)
Ajith Kallambella
Sheriff
Posts: 5782
posted 24 years ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
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.
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.
Open Group Certified Distinguished IT Architect. Open Group Certified Master IT Architect. Sun Certified Architect (SCEA).
Farhan Tariq
Ranch Hand
Posts: 54
posted 24 years ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
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
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 |






