Hi Ching
I don't think I understand the question. A Thread object is like any
other Java object:
-- You can instantiate it
-- You can directly access its public fields and call its public methods
-- You can directly (without instantiate an object) access the class
static public fields and call the class static public methods.
Hope it helps
Mihai
Kim Ching Koh a écrit :
Hi,
What is the difference between the "usual" java objects vs Thread
objects? Are Thread objects actually sharing object/instance
variables, as compare to usual object where each object holds their
object variable. I did some experiement, it seem I can't access into
thread object variables, hence it seems thread objects share
object/instance variables? For example, i can invoke setInt() method
of this thread object:
private static class MessageLoop implements Runnable {
int id = 0;
public void setInt(int id){
this.id <http://this.id> = id;
}
public void run() {
String importantInfo[] = {
"Mares eat oats",
"Does eat oats",
"Little lambs eat ivy",
"A kid will eat ivy too"
};
try {
for (int i = 0; i < importantInfo.length; i++) {
//Pause for 4 seconds
Thread.sleep(4000);
//Print a message
threadMessage(importantInfo[i]);
}
} catch (InterruptedException e) {
threadMessage("I wasn't done!");
}
}
}
Regards
KC
--
To post to this group, send email to
[email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/javaprogrammingwithpassion?hl=en
--
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/javaprogrammingwithpassion?hl=en