Re: Thread and Garbage collection
On Thu, May 18, 2000 at 10:15:08AM +0700, yangyuex wrote: > Thanks very much! > > What's your mean: > > "which BTW > sets *INTERRUPTED* flag in the Thread object, > The use of the an instance variable is redundant since the thread > already has > a flag designed for that perpose." > > I also think this is a feasible way. > Because I think the root for garbage collection are > implementation-dependant. > Depending on the implementation and support for native methods, > roots for garbage collection may be contained in: > > o All pointers in all stack frames of the stacks of all JVM threads. > These include pointers in the local variable areas of the frames > and pointers in the operand stacks of the frames. > > o All pointers to static fields of classes in the class and method > area of the JVM. > > o native methods, Native methods themselves do not provide roots, but the JNI interface does define semantics for effectively adding objects involved in a JNI invocation to the root set. > o registers of the JVM (for optimization) Well the JVM doesn't really have registers, it's just got a stack. ;-) Seriously though, a lot of JVM's use conservative GC which makes it possible for objects to be marked as reachable despite the fact that they aren't. > From here, I think there is no way for the GC to collect an alive thread > although there is no reference refer to it. Actually, if a thread is still alive there is still a pointer to it, otherwise, how could the Thread.enumerate() find it? ;-) > So, by interrupt method here, which force run() method to finish, which > is a safe way to make the thread dead. --Chris -- To UNSUBSCRIBE, email to [EMAIL PROTECTED] with a subject of "unsubscribe". Trouble? Contact [EMAIL PROTECTED]
Objects and Serialization
Dear Sir I am new to object serialization. I want to use some graph package of which the classes do not extend from serializable interface, but I need transfer the objects of my classes which have instance of graph class, will I have problem if I only extent serializable in the definition of my own classes? Thanks yangyuexiang -- To UNSUBSCRIBE, email to [EMAIL PROTECTED] with a subject of "unsubscribe". Trouble? Contact [EMAIL PROTECTED]
Re: Thread hangs, signals and JNI
> Vasile GABURICI writes: Vasile> I am not questioning your knowledge on the SIGUSR2 issue, Vasile> but note that other JVMs do not seem to use it. For Vasile> instance Sun's JDK 1.2.2 for Linux does NOT use SIGUSR2. I Vasile> have checked the source. Unfortunately their Vasile> implementation of native threads on Linux is broken in Vasile> other ways (stack corruption on pthread_join), so I cannot Vasile> use it. Sun's native threads code is a very early snapshot of our native threads implementation and doesn't have much in common with our current code. Juergen -- Juergen Kreileder, Blackdown Java-Linux Team http://www.blackdown.org/java-linux.html JVM'01: http://www.usenix.org/events/jvm01/ -- To UNSUBSCRIBE, email to [EMAIL PROTECTED] with a subject of "unsubscribe". Trouble? Contact [EMAIL PROTECTED]
Re: Thread and Garbage collection
All thread object contain a private boolean varible flag that is set and reset
based on the the new STATE of the thread ( ie INTERRUPTED , NOT INTERRUPTED ).
The thread APIs like sleep() , wait() or join() will throw and InterruptedException when the
thread's state changes from *NOT INTERRUPTED* to *INTERRUPTED* by a call to
interrupt(). Threads that are not in sleep,wait or join( just plain BLOCKED ) mode can
check the status of the flag using the interrupted() api.
I hope this helps.
Cheers
Chris
yangyuex wrote:
Thanks very much!
What's your mean:
"which BTW
sets *INTERRUPTED* flag in the Thread object,
The use of the an instance variable is redundant since the thread already
has
a flag designed for that perpose."
I also think this is a feasible way.
Because I think the root for garbage collection are implementation-dependant.
Depending on the implementation and support for native methods,
roots for garbage collection may be contained in:
o All pointers in all stack frames of the stacks of all JVM threads.
These include pointers in the local variable areas of the frames
and pointers in the operand stacks of the frames.
o All pointers to static fields of classes in the class and method
area of the JVM.
o native methods,
o registers of the JVM (for optimization)
From here, I think there is no way for the GC to collect an alive
thread although there is no reference refer to it.
So, by interrupt method here, which force run() method to finish, which
is a safe way to make the thread dead.
Christopher Hinds wrote:
In a previous post I made an error in the code example
it should look like the following.
Allowing for the thread acsessing the hashtable extracting the
referenenced Thread object and calling Thread.interupt() , which BTW
sets *INTERRUPTED* flag in the Thread object,
The use of the an instance variable is redundant since the thread already
has
a flag designed for that perpose.
Example :
<<< some other thread code
Thread t = htbl.get("X");
t.interrupt();
>>
class x extends Thread {
void run() {
try{
while(true){
if(interrupted()){
// do all your clean up here
return;
}
// do something else here
}
}
catch(
InterruptedException e){
e.printStactTrace();
return;
}
}
Cheers
Chris
Christopher Hinds wrote:
I am assuming you are using jdk1.2 and in that
case the stop method has been
depricated. You should use use Thread interrupt to stop the thread.
When you remove the Thread object from the hashtable issue a Thread.interrup()
call so the thread object unwinds correctly and exits the run method
then set the obejct reference to null so on the next GC pass the dead thread
object will be garbage collected.
Example:
class xx implements Runnable
{
// class
code here
void run()
{
try {
while(true) {
// some code here
}
}
catch(InterruptedException e) {
e.printStackTrace();
return;
}
}
}
}
Cheers
Chris
yangyuex wrote:
Hi
I have several threads in one hashtable.
When I remove one of them, whether this thread still consume CPU etc
resources?
That's to say, if I will not need one thread, whether I must stop or
destory it explictly or
just remove it from hashtable for garbage collection?
I am not sure how JVM schedules multiple threads.
Thanks very much!
yangyuexiang
--
To UNSUBSCRIBE, email to [EMAIL PROTECTED]
with a subject of "unsubscribe". Trouble? Contact [EMAIL PROTECTED]
Ascii
Hi All I am still fairly new to java. I am writing an app that communicates by rs232 to a motor controller. Part of the packet that I send to it requires an ascii STX and ETX are there any escape sequences for these characters. If not- Any Ideas. STX and ETX are binary 2 and 3. Is there a way to cast the integer value to a character w/o making it ascii 2 and 3. Rick R. -- To UNSUBSCRIBE, email to [EMAIL PROTECTED] with a subject of "unsubscribe". Trouble? Contact [EMAIL PROTECTED]
JVM INSTR pop;????????
Hi,
Who can tell me what's mean of
"JVM INSTR pop; " in my attatched file.
When I compiler the attatched file,
the compiler complains that it does not support
"goto", so I decided to understand this small program that
I can rewrite it.
Thanks very much!
Yangyuexiang
public boolean isTree()
{
boolean flag;
String s;
Enumeration enumeration;
flag = true;
if(this instanceof Tree)
return true;
s = defUniqueSystemKey(null, false);
enumeration = enumerateVertices();
goto _L1
_L4:
Vertex vertex = (Vertex)enumeration.nextElement();
goto _L2
JVM INSTR pop ;
continue; /* Loop/switch isn't completed */
_L2:
if(vertex.systemdict.getBoolean(s) || _isTreeBranch(vertex, s))
continue; /* Loop/switch isn't completed */
flag = false;
break; /* Loop/switch isn't completed */
_L1:
if(enumeration.hasMoreElements()) goto _L4; else goto _L3
_L3:
undefSystemKey(s);
return flag;
}
Re: JVM INSTR pop;????????
yangyuex wrote: > > Hi, > > Who can tell me what's mean of > > "JVM INSTR pop; " in my attatched file. I don't think this line is a legal Java statement. It looks like 'inline assembly' for the JVM. You will need a Java compiler that understands this sort of things. > When I compiler the attatched file, > the compiler complains that it does not support > "goto", so I decided to understand this small program that > I can rewrite it. Again, it look like inline assembly for the JVM. -- Weiqi Gao [EMAIL PROTECTED] -- To UNSUBSCRIBE, email to [EMAIL PROTECTED] with a subject of "unsubscribe". Trouble? Contact [EMAIL PROTECTED]
Re: JVM INSTR pop;????????
Hi, At Sat, 20 May 2000 20:03:11 +0700, yangyuex <[EMAIL PROTECTED]> wrote: > Who can tell me what's mean of > > "JVM INSTR pop; " in my attatched file. The `pop' instruction remove away a word from top of Java stack, and it often appears in the context that method returns a value but the caller never use it. (For more information, see Java Virtual Machine Specification) > When I compiler the attatched file, > the compiler complains that it does not support > "goto", so I decided to understand this small program that > I can rewrite it. I hope attached file can explain you what the code fragment you attached do. ;-) *Warning* I think the code fragment you attached is from some decompiler's output like Mocha, so I cannot decide whether my idea is correct or not because it is like decompiler's intermediate code and it can be dropped some informations. -- MARUYAMA Fuyuhiko <[EMAIL PROTECTED]> Matsuoka laboratory, Department of Mathematical and Computing Sciences, Graduate School of Tokyo Institute of Technology. Temp.java
Changes to javac?
Just wanted to say thanks, first of all, for making such a clean, useful website. You have much more content than most sites, and it's actually easy to navigate. I've downloaded the JDK source from Sun, and have spent a little time tangling with the javac package. I need a java compiler that A) lets me compile to / from bytearrays, not just files and B) lets me modify the parse tree once it has been loaded. javac seemed like a good candidate, but it's not really suited for either of these, as far as I can tell (the parse tree is an unintelligable heap, and the compiler classes are fairly well hard coded for files). I know you guys don't specialize in questions like this, but do to the fact that you seem to have an extreme level of competence (and, I swear I'm not trying to flatter) combined with the lack of internal / technical support for questions like this at Sun... I figured you might be able to help me. If not, do you have any advice for other discussion groups, etc? -- To UNSUBSCRIBE, email to [EMAIL PROTECTED] with a subject of "unsubscribe". Trouble? Contact [EMAIL PROTECTED]
Re: Changes to javac?
Zach Buckner wrote: > Just wanted to say thanks, first of all, for making such a clean, useful > website. You have much more content than most sites, and it's actually > easy to navigate. > > I've downloaded the JDK source from Sun, and have spent a little time > tangling with the javac package. I need a java compiler that A) lets me > compile to / from bytearrays, not just files and B) lets me modify the > parse tree once it has been loaded. javac seemed like a good candidate, > but it's not really suited for either of these, as far as I can tell > (the parse tree is an unintelligable heap, and the compiler classes are > fairly well hard coded for files). You might find the Kopi Java compiler more to your liking. It's open source, and more friendly to the sort of hacking you want to do: http://www.dms.at/kopi/index.html Nathan Meyers [EMAIL PROTECTED] > > > I know you guys don't specialize in questions like this, but do to the > fact that you seem to have an extreme level of competence (and, I swear > I'm not trying to flatter) combined with the lack of internal / > technical support for questions like this at Sun... I figured you might > be able to help me. If not, do you have any advice for other discussion > groups, etc? > > -- > To UNSUBSCRIBE, email to [EMAIL PROTECTED] > with a subject of "unsubscribe". Trouble? Contact [EMAIL PROTECTED] -- To UNSUBSCRIBE, email to [EMAIL PROTECTED] with a subject of "unsubscribe". Trouble? Contact [EMAIL PROTECTED]
