Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Getting thread info from sub-threads.




On Aug 21, 2006, at 1:56 AM, bsd5tu1 wrote:


If the method we launch creates another thread within it,

How is it doing this? One thing you might do is subclass Thread and then you can add whatever additional functionality you want to the new class.


e.g.

public void start() {
ThreadTracker.put(this.getName(),"started"); // Or ThreadTracker.put (getName(),getThreadInfo("started")); if more involved
super.start();
}


It sounds like possibly you aren't actually creating a new thread.
static has nothing to do with whether or not something changes. It refers to whether a field or method applies to each instance of a class or to the single instance of the class itself.


e.g.
public class CounterClass {

static int counter = 1;

increasing this to 2 increases it for the class itself, meaning every instance of the class would now have the 2 value. Get rid of the static and you increase it only for the current instance, every other instance could have their own independent value.
A static method again applies to the whole class and not to each single instance.
You need a static method say to change a static field...


public static void increment() { counter++; }

Because static applies to the class is why when you start synchronizing threads with the method modifier
public synchronized static void increment() { counter++; }
you hold the lock on CounterClass.class


While if it's not static
public synchronized void increment() { counter++; }
you hold the lock only for this single instance of a CounterClass

Which would be pretty much how static applies to Threading.


Mike Hall mikehall at spacestar dot net http://www.spacestar.net/users/mikehall http://sourceforge.net/projects/macnative



Attachment: smime.p7s
Description: S/MIME cryptographic signature

 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Java-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/java-dev/email@hidden

This email sent to email@hidden

References: 
 >Getting thread info from sub-threads. (From: bsd5tu1 <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.