What class called my method?

I have tried using the StringWriter and the printStackTrace() methodology for finding out the name of the method that actually called my class and it works fine. But the problem is that the execution time is too high (abt 70msec). I need a better and more efficient way of finding this out.
Does someone have an idea of how to do this?
Regards,
Manoj Rathod.

Ok, this was my test code:
    public class MethodTrace {
        public static void main (String[] args) {
            method3(false);
        public static void method1 (boolean stop) {
            StackTraceElement e[] = (new Throwable()).getStackTrace();
            System.out.println("method1: called by " + e[1].getMethodName());
            if (!stop) method3(false);
        public static void method2 (boolean stop) {
            StackTraceElement e[] = (new Throwable()).getStackTrace();
            System.out.println("method2: called by " + e[1].getMethodName());
            if (!stop) method1(true);
        public static void method3 (boolean stop) {
            StackTraceElement e[] = (new Throwable()).getStackTrace();
            System.out.println("method3: called by " + e[1].getMethodName());
            if (!stop) method2(false);
    };And this was the output:
    method3: called by main
    method2: called by method3
    method1: called by method2As for the speed, I don't know. It's cleaner than using printStackTrace(), and I would think it would be faster. But I'm not sure.
Why do you need to know the calling method, though? Perhaps there is some other, faster way to do what you want to do that doesn't have to use any stack tracing stuff at all.
Or maybe you could just call the method, passing the name of the calling method as a String parameter:
    public void excellent (String caller) {
        System.out.println("Called by " + caller);
    public void superb () {
        excellent("superb");
    public void hard () {
        excellent("hard");
    };Lemme know if you find out anything interesting.
Jason Cipriani
[email protected]
[email protected]

Similar Messages

  • What class calls the method?

    If there is a method in a class that could be called by any one of, lets say, one hundred other classes, in that method is there a way of printing out the name of the class that called it ?
    So if class Xyz calls the method I would like to just do a println in the method saying that class Xyz called it ?

    Yup... Thread.currentThread().getStackTrace();
    package krc.utilz;
    import java.io.PrintStream;
    public class Tracer
      public static PrintStream out = null;
      public boolean enabled = true;
      public enum Format { LONG, SHORT }
      public Format format;
      public Tracer() {
        this(System.err, Tracer.Format.LONG);
      public Tracer(PrintStream out) {
        this(out, Tracer.Format.LONG);
      public Tracer(Format format) {
        this(System.err, format);
      public Tracer(PrintStream out, Format format) {
        this.out = out;
        this.format = format;
      public String toString() {
        return get(5);
      public String get() {
        return get(2);
      public String get(int i) {
        StackTraceElement[] st = Thread.currentThread().getStackTrace();
        if (i>=st.length) i = st.length-1; //don't go past top of stack
        StackTraceElement t = st;
    String s = t.getFileName()+":"+t.getLineNumber()+":";
    if (this.format == Format.LONG) {
    s += t.getClassName()+"."+t.getMethodName();
    return(s);
    public void debug(String msg) {
    if(!enabled)return;
    out.println("DEBUG: "+msg);
    public void print(String msg) {
    if(!enabled)return;
    if (out==null) return;
    out.println(get(3)+" : "+msg);
    public void print() {
    if(!enabled)return;
    if (out==null) return;
    out.println(get(3));
    public void print(int i) {
    if(!enabled)return;
    if (out==null) return;
    out.println(get(i));
    public static String getCurrentMethodName() {
    StackTraceElement[] st = Thread.currentThread().getStackTrace();
    return(st[2].getMethodName());

  • To what class does this method belong?

    If one sees in the documentation something like
    - (retType *) text1:(Type1 *)aType1 text2:(Type2 *)aType2;
    then to what class does this method belong? I do not see in the Objective-C documentation any way that one can tell without the 'context' in which the method is declared or defined. This makes reading the documentation very difficult (for me). What you see is not what you get. There is stuff missing.
    In my world there is no difficulty in determining the class to which a method belongs. It is stated explicitly in the method name. For example:
    PROCEDURE (self: MyClass) methodName (arg1: Type1; arg2: Type2);
    and one sees that 'methodName' belongs to 'MyClass'.
    In Objective-C how does one know the class to which a method belongs? Is it only determined by context, that is, by the fact that it is within the @implementation section or that it is within the @interface section? If that is the case then I would think that in documentation one should always be required to assert something like:
    <<MyClass>> -(retType *) text1:(Type1 *)aType1 ...
    -Doug Danforth

    PeeJay2,
    I think I now have the distinctions needed but still have a question about what you said. But first here is my current understanding. A "method" is by definition bound to *at least* one class whereas a "message" need not be bound to any class. Hence one can send any message to any class and it will either be handled or ignored. A message looks like a method signature (and maybe one but is not constrained to be one).
    The difference between C++ and Objective-C is that in C++ method calls are not messages sent to a receiver. They are just calls of the method for the dynamically bound object. That method must be syntactically correct at compile time whereas messages need not be syntactically correct for any receiver. At least that is my current understanding.
    Now my question. You state that "casting the receiver of a message will in no way alter the flow of the code". I attempted to test this with a simple program but ran into a problem (see my new posting "Multiple classes in one file?").
    Assume the following
    @class Child : Parent
    Child *child = [[Child alloc] init];
    Parent *parent = [[Parent alloc] init];
    Parent *bar;
    bar = child;
    [bar doSomething]; // (C) call to child's doSomething method?
    [(Parent *)bar doSomething]; // (P) call to parent's doSomething method?
    You comment seems to say that both case (C) and (P) give the same result. If they do then which result is it the parent's or the child's method (assuming that the child has indeed reimplemented the parent's method)? Have I understood you correctly?
    -Doug Danforth

  • Class call a method

    Hi,
    If you have numerous methods in a class, can you just call them like so:
    // in the .fla file
    var john:Person = new Person(63,150); // creates a new person named john 63" and 150lbs.
    john.weight(180); // changes johns weight to 180lbs.
    // in the .as file
    package {
        import flash.display.MovieClip;
        public class Person extends MovieClip {
            public var _perHeight:Number;
            public var _weight:Number;
          public function Person(perHeight:Number, weight:Number) {
                _perHeight=perHeight;
                _weight=weight;
                this.perHeight=_perHeight;
                this.weight=_weight;
            public function changeWeight(newWeight) {
                this.weight=newWeight;
    I must be calling the method completely wrong? I get this error:
    1061: Call to a possibly undefined method weight through a reference with static type Person.

    That is because the method is called "changeWeight" and you are using "weight."
    But what you really want is probably not a method but rather a getter/setter that acts like a property -- or maybe you just want a property.
    So in your class you would have this:
    package {
        import flash.display.MovieClip;
        public class Person extends MovieClip {
            private var _perHeight:Number;
            private var _weight:Number;
            private var _age:Number;
            public function Person(perHeight:Number, weight:Number) {
                _perHeight=perHeight;
                _weight=weight;
            public function set weight(num:Number):void{
                _weight=num;
           public function get weight():Number{
              return _weight;
    Then in your code (after creating a person instance):
    john.weight=180;// changes john's weight to 180.
    The cool thing about getters and setters is that they act just like a property when you use them, but they allow for a whole function call at the other end and can do various things based on the inputs.
    Also variable that start with an underscore are usually private variables. So in this case _weight, _age, and _perHeight would be private -- you couldn't access them directly through the john instance for example. And you would have appropriate getters and setters for them. For example you might make an age setter that didn't allow the number to be set as smaller than the current value or something.

  • Telling which class called your method

    Does anybody know a way you can tell which class is calling your method? I mean:
    class A {
    public static void main(String args[]) {
    new A.doIt();
    void doIt() {
    B b = new B();
    b.callMe();
    class B {
    public void callMe() {
    String whoDidIt;
    whoDidIt=[stuff i'm asking for];
    System.out.println("I was called from an instance of class " + whoDidIt);
    How can I get that code to print "I was called from an instance of class A"???
    Lots of thanks in advance

    Pass the calling object to callMe as a parameter, egB b = new B();
    b.callMe(this);callMe becomes:
    public void callMe(Object caller)
       System.out.println("I was called from an instance of class " + caller.getClass());
    }Of course, there is nothing to stop anyone who calls the method passing a different object and confusing callMe.

  • Which object called the method

    Suppose there is a class A which has three objects a1,a2,a3 and a method m. Now I'd like to know which particular object has called the method m.

    >
    which particular object has called the method
    What class called my method
    http://developer.java.sun.com/developer/qow/archive/104
    a.The advice in the posted link is unreliable as the format of printStackTrace() is not standardized. A more reliable way to find out the calling class is to use SecurityManager.getClassContext() or Throwable.getStackTrace() [in JDK 1.4+].
    However, it is not clear whether the original poster wanted to know the calling class or the calling object. In the latter case there is no easy way except for modify the signature of method m to accept the reference to the calling object.
    Vlad.

  • Is knowing of Class Name, which called current method, possible?

    Hallo everyone,
    My method is called from inside some method of some class. Can I know which class called my method.
    In other words I would like to know is that possible to have a name of class from which my current method is called? It's sometrhing like I need an access to the call stack.
    thanks!

    You can do the same thing before 1.4 as well:
          Throwable t;
          PrintStream ps;
          PrintWriter pw;
          String str;
          StringBuffer sb;
          StringWriter st;
          t = new Throwable();
          st = new StringWriter();
          pw = new PrintWriter(st);
          t.printStackTrace(pw);
          sb = st.getBuffer();
          str = sb.toString();You now have the stack as a String in the variable str.
    The problem is that you have to parse the String to separate methods from classes and so on. And different platform may produce slightly different string representations of the stack.
    So, it is easier in Java 1.4

  • What class handles deciding if method called is Private/Public,etc?

    What class is the one that handles whether or not the caller has access to a method (i.e. when they call, it checks that it is private or whatever, and then allows calling or not)?

    No class at all is responsible for that, but the virtual machine.
    Plese read 6.6.1 and 15.12.2.1 in the Java Language Specification

  • Calling a method from a super class

    Hello, I'm trying to write a program that will call a method from a super class. This program is the test program, so should i include extends in the class declaration? Also, what code is needed for the call? Just to make things clear the program includes three different types of object classes and one abstract superclass and the test program which is what im having problems with. I try to use the test program to calculate somthing for each of them using the abstract method in the superclass, but its overridden for each of the three object classes. Now to call this function what syntax should I include? the function returns a double. Thanks.

    Well, this sort of depends on how the methods are overridden.
    public class SuperFoo {
      public void foo() {
         //do something;
      public void bar(){
         //do something
    public class SubFoo extends SuperFoo {
       public void foo() {
          //do something different that overrides foo()
       public void baz() {
          bar(); //calls superclass method
          foo(); //calls method in this (sub) class
          super.foo(); //calls method in superclass
    }However, if you have a superclass with an abstract method, then all the subclasses implement that same method with a relevant implementation. Since the parent method is abstract, you can't make a call to it (it contains no implementation, right?).

  • Calling a method of one class from another withing the same package

    hi,
    i've some problem in calling a method of one class from another class within the same package.
    for eg. if in Package mypack. i'm having 2 files, f1 and f2. i would like to call a method of f2 from f1(f1 is a servlet) . i donno exactly how to instantiate the object for f2. can anybody please help me in this regard.
    Thank u in advance.
    Regards,
    Fazli

    This is what my exact problem.
    i've created a bean (DataBean) to access the database. i'm having a servlet program (ShopBook). now to check some details over there in the database from the servlet i'm in need to use a method in the DataBean.
    both ShopBook.java and DataBean.java lies in the package shoppack.
    in ShopBook i tried to instantiate the object to DataBean as
    DataBean db = new DataBean();
    it shows the compiler error, unable to resolve symbol DataBean.
    note:
    first i compiled DataBean.java, it got compiled perfectly and the class file resides inside the shoppack.
    when i'm trying to compile the ShopBook its telling this error.
    hope i'm clear in explaining my problem. can u please help me?
    thank u in advance.
    regards,
    Fazli

  • Calling a method from abstarct class

    Hi Experts,
    Am working on ABAP Objects.
    I have created an Abstract class - with method m1.
    I have implemented m1.
    As we can not instantiate an abstract class, i tried to call the method m1 directly with class name.
    But it it giving error.
    Please find the code below.
    CLASS c1 DEFINITION ABSTRACT.
      PUBLIC SECTION.
        DATA: v1 TYPE i.
        METHODS: m1.
    ENDCLASS.                    "c1 DEFINITION
    CLASS c1 IMPLEMENTATION.
      METHOD m1.
        WRITE: 'You called method m1 in class c1'.
      ENDMETHOD. "m1
    ENDCLASS.                    "c1 IMPLEMENTATION
    CALL METHOD c1=>m1.
    Please tell me what is wrong and how to solve this problem.
    Thanks in Advance.

    Micky is right, abstract means not to be instantiated. It is just a "template" which you can use for all subsequent classes. I.e you have general abstract class vehicle . For all vehicles you will have the same attributes like speed , engine type ,  strearing , gears etc and methods like start , move etc.
    In all subsequent classes (which inherit from vehicle) you will have more specific attributes for each. But all of these classes have some common things (like the ones mentioned above), so they use abstract class to define these things for all of them.
    Moreover there is no sense in creating instance (real object) of class vehicle . What kind of physical object would vehicle be? there is no such object in real world, right? For this we need to be more precise, so we create classes which use this "plan" for real vehicles. So the abstract class here is only to have this common properties and behaviour defined in one place for all objects which will have these. Abstract object however cannot be created per se. You can only create objects which are lower in hierarchy (which are specific like car , ship, bike etc).
    Hope this claryfies what we need abstract classes for.
    Regards
    Marcin

  • Can't add list element when calling a method from another class

    I am trying to call a method in another class, which contains code listmodel.addElement("text"); to add an element into a list component made in that class.
    I've put in System.out.println("passed"); in the method just to make sure if the method was being called properly and it displays normally.
    I can change variables in the other class by calling the method with no problem. The only thing I can't do is get listmodel.addElement("text"); to add a new element in the list component by doing it this way.
    I've called that method within it's class and it added the element with no problem. Does Java have limitations about what kind of code it can run from other classes? And if that's the case I'd really like to know just why.

    There were no errors, just the element doesnt get added to the list by doing it this way
    class showpanel extends JPanel implements ActionListener, MouseMotionListener {
           framepanel fp = new framepanel();
           --omitted--
         public void actionPerformed(ActionEvent e){
                  if(e.getSource() == button1){
                       fp.addLayer();
    /*is in a different class file*/
    class framepanel extends JPanel implements ActionListener{
            --omitted--
         public void addLayer(){
              listmodel.addElement("Layer"+numLayer);
              numLayer++;
    }

  • Simple enough but... calling a method from another class

    Hi all,
    I know it's simple enough, although I can't see where I'm going wrong for some reason. Basically I've got a class which extends JPanel but when I try to call one of its methods from my main class I get an error. The relevant code (I hope) is:
    Main.java
    import java.awt.BorderLayout;
    import javax.swing.UIManager;
    public class Main extends JFrame implements ActionListener {
         JFrame frame;
         public static JPanel statusBar;
         public Main() {
              // Add a status bar
              statusBar = new StatusBar();
              mainPanel.add( statusBar, BorderLayout.SOUTH );
              setContentPane( mainPanel );
         public static void setStatusBarText( String s ) {
              statusBar.setStatusText("Test");
    StatusBar.java
    import java.awt.Color;
    import javax.swing.SwingConstants;
    public class StatusBar extends JPanel {
         private int barWidth;
         private static JLabel status;
         public StatusBar() {
              super();
              //barWidth = Main.getProgramWidth();
              //setPreferredSize( new Dimension(barWidth,22) );
              setLayout( new FlowLayout( FlowLayout.LEADING ) );
              setBorder( BorderFactory.createMatteBorder(1, 0, 0, 0, new Color(160,160,160) ) );
              status = new JLabel("Test", SwingConstants.LEFT);
              //status.setVerticalAlignment( SwingConstants.CENTER );
              add( status );
         protected void setStatusText( String s ) {
              status.setText( s );
              revalidate();
    }The "statusBar.setStatusText("Test");" call in the main class file doesn't work and I get the error:
    >
    cannot find symbol
    symbol : method setStatusText(java.lang.String)
    location: class javax.swing.JPanel
    statusBar.setStatusText("Test");
    >
    Any ideas what I'm doing wrong? I created an instance of the StatusBar class called statusBar, then I use this to call the setStatusText() method (via statusBar.setStatusText()) which I thought was all correct, then it doesn't work? Even if there's an easier way to do what I want to achieve (i.e. update a JLabel from the 'central' main class file instead of setting the JLabel to static and having every class call it directly), I'd appreciate knowing where I'm going wrong here nonetheless.
    Many thanks,
    Tristan

         public static JPanel statusBar;
         public static void setStatusBarText( String s ) {
              statusBar.setStatusText("Test");
    >
    cannot find symbol
    symbol : method setStatusText(java.lang.String)
    location: class javax.swing.JPanel
    statusBar.setStatusText("Test");
    >The type of variable statusBar is JPanel. That's all the compiler takes into account. It's irrelevant that at some point in the program the type of the object pointed to by this variable is a subclass of JPanel (because at another point it might be an instance of another subclass, or of JPanel itself.

  • How to call a method in private section of a class in the public section

    Hi Everybody,
    i have written a method(meth1) in the private section of a class(C1).
    it is as follows
    class C1 definition.
    private section.
    methods: meth1 importing im_dt1 like tp1
                                             im_dt2 like tp2
                                             im_dt3 like tp3
                                             im_dt4 like tp4
                               returning value(re_dt1) like tp5.
    endclass.
    i have the final data that has to be displayed in internal table re_dt1.
    now my question is how to call  this method present in private section into public section and display the data present in re_dt1.
    Thanks,
    learning.abap.

    Hi,
    what you need is one public method being called at start-of-selection. Within this the private methods have to be called.
    The question is, why has the method for reading the database tables to be private? If you have only one private method reading all database tables the public method being called at start-of-selection will only consist of a call-method statement.
    This seems to be one call to much.
    The logic for reading the different database tables is hidden inside the class anyway.
    Is there any further logic reading the different database tables?
    Have always all table to be read? If not another approach would be one private method for each database table being called by a public method deciding which table has to be read:
    public section.
    methods get_data returning value(re_Dt1).
    private section.
    methods:
    get_table_a returning value(im_dt1),
    get_table_b returning value(im_dt2),
    get_table_c returning value(im_dt3),
    get_table_d returning value(im_dt4),
    combine_data importing im_dt1
                                    im_dt2
                                    im_dt3
                                    im_dt4
                            returning value(re_dt1).
    *- implementation of public method:
    method get_data.
      data: lt_dt1 ...
               lt_dt2,
               lt_dt3,
               lt_dt4.
    * here decide which tables have to be read:
    lt_dt1 = get_table_a( ).
    lt_dt2 = get_table_b( ).
    lt_dt3 = get_table_c( ).
    lt_dt4 = get_table_d( ).
    re_dt1 = combine_data( i_dt1 = lt_dt1
                                           i_dt2 = lt_dt2
                                           i_dt3 = lt_dt3
                                           i_dt4 = lt_dt4 ).
    endmethod.
    *- implementation of private methods
    method get_table_a.
    endmethod.
    method get_table_b.
    endmethod.
    method get_table_c.
    endmethod.
    method get_table_d.
    endmethod.
    method combine_data.
    endmethod.
    Regards
    Dirk

  • Calls to methods in a class that extends Thread

    Hello,
    I have some code that I am initiating from within an ActionListener that is part of my programs GUI. The code is quite long winded, at least in terms of how long it takes to perform. The code runs nicely, however once it is running the GUI freezes completely until operations have completed. This is unacceptable as the code can take up to hours to complete. After posting a message on this forum in regard to the freezing of the GUI it was kindly suggested that I use multi-threading to avoid the unwelcome program behaviour.
    The code to my class is as follows:
    public class FullURLAddress
      private boolean success_flag = true;
      private BufferedReader iN;
      private Document dT;
      private EditorKit kT;
      private Element lmNt;
      private ElementIterator lmIterate;
      private XURL[] compAddress;
      private int countX = 0;           //Tracks Vector vT's size.
      private int countY = 0;           //Tracks Vector vS's size.
      private int xURLcount = 0;        //Tracks XURL objects instantiated by this FullURLAddress object.
      private SimpleAttributeSet simpAtSet;
      private String aURL;              //Contains original (Xtended) URL!
      private String fileType;
      private String indexContent;
      private String[] parseURL;
      private String[] finalStrings;
      private String[] sortStrings;
      private URL indexConnect;
      private URLConnection iconn;
      private Vector vT;            //Stores href information, from targeted URL's HTML souce code.
      private Vector vS;            //Stores sorted HREF info ".jpg" and ".gif" only (no: png, tiff, etc).
      public FullURLAddress(String aURL)
        this.aURL = aURL;
        try{
          indexConnect = new URL(aURL);
          iconn = indexConnect.openConnection();
          iN = new BufferedReader(new InputStreamReader(iconn.getInputStream()));
            /* Document creation, analysis objects instantiated */
          vT = new Vector();
          vS = new Vector();
          kT = new HTMLEditorKit();
          dT = kT.createDefaultDocument();
          dT.putProperty("IgnoreCharsetDirective", Boolean.TRUE);
            /* Iterate through document and store all HREF values */
          kT.read(iN, dT, 0);
          lmIterate = new ElementIterator(dT);
          while((lmNt = lmIterate.next()) != null)
            simpAtSet = (SimpleAttributeSet)lmNt.getAttributes().getAttribute(HTML.Tag.A);
            if(simpAtSet != null)         //As long as there are A tags to be read...
              vT.addElement(simpAtSet.getAttribute(HTML.Attribute.HREF));
              countX++;//Tracks number of HREF occurences occur, giving better control of the Vector.
        }catch(MalformedURLException e){
          success_flag = false;
          System.out.println("FullURLAddress object has encountered a "+
                             "MalformedURLException at: "+aURL);
        }catch(IOException e){
          e.getMessage();
          success_flag = false;
        }catch(BadLocationException e){
          e.getMessage();
          success_flag = false;
        /* Searches through all HREF attributes that are now stored in Vector
           vT for occurences of the character string ".htm" */
        sortStrings = new String[countX];
        for(int i=0;i<countX;i++)
          sortStrings[i] = (String)vT.elementAt(i); //Vector Strings transfered into array.
          if(sortStrings.endsWith("gif")) // Does href value end with ".jpg"?
    vS.addElement(sortStrings[i]); // If so add it to the sorted Vector vS.
    countY++;
    if(sortStrings[i].endsWith("GIF"))
    vS.addElement(sortStrings[i]);
    countY++;
    if(sortStrings[i].endsWith("jpg")) // Does href value end with ".jpg"?
    vS.addElement(sortStrings[i]); // If so add it to the sorted Vector vS.
    countY++;
    if(sortStrings[i].endsWith("JPG"))
    vS.addElement(sortStrings[i]);
    countY++;
    finalStrings = new String[countY];
    for(int j=0;j<countY;j++)
    finalStrings[j] = (String)vS.elementAt(j);
    public int getCount()
    return countY; //Returns number of instances of htm strings
    } //ending with either "jpg" or "gif".
    public String[] xurlAddressDetails()
    return finalStrings;
    I have changed the above code to make use of multithreading by making this class extend Thread and implementing the run() method as follows:
    public class FullURLAddress extends Thread
      private boolean success_flag = true;
      private BufferedReader iN;
      private Document dT;
      private EditorKit kT;
      private Element lmNt;
      private ElementIterator lmIterate;
      private XURL[] compAddress;
      private int countX = 0;           //Tracks Vector vT's size.
      private int countY = 0;           //Tracks Vector vS's size.
      private int xURLcount = 0;        //Tracks XURL objects instantiated by this FullURLAddress object.
      private SimpleAttributeSet simpAtSet;
      private String aURL;              //Contains original (Xtended) URL!
      private String fileType;
      private String indexContent;
      private String[] parseURL;
      private String[] finalStrings;
      private String[] sortStrings;
      private URL indexConnect;
      private URLConnection iconn;
      private Vector vT;            //Stores href information, from targeted URL's HTML souce code.
      private Vector vS;            //Stores sorted HREF info ".jpg" and ".gif" only (no: png, tiff, etc).
      public FullURLAddress(String aURL)
        this.aURL = aURL;
      public void run()
        try{
          indexConnect = new URL(aURL);
          iconn = indexConnect.openConnection();
          iN = new BufferedReader(new InputStreamReader(iconn.getInputStream()));
            /* Document creation, analysis objects instantiated */
          vT = new Vector();
          vS = new Vector();
          kT = new HTMLEditorKit();
          dT = kT.createDefaultDocument();
          dT.putProperty("IgnoreCharsetDirective", Boolean.TRUE);
            /* Iterate through document and store all HREF values */
          kT.read(iN, dT, 0);
          lmIterate = new ElementIterator(dT);
          while((lmNt = lmIterate.next()) != null)
            simpAtSet = (SimpleAttributeSet)lmNt.getAttributes().getAttribute(HTML.Tag.A);
            if(simpAtSet != null)         //As long as there are A tags to be read...
              vT.addElement(simpAtSet.getAttribute(HTML.Attribute.HREF));
              countX++;//Tracks number of HREF occurences occur, giving better control of the Vector.
        }catch(MalformedURLException e){
          success_flag = false;
          System.out.println("FullURLAddress object has encountered a "+
                             "MalformedURLException at: "+aURL);
        }catch(IOException e){
          e.getMessage();
          success_flag = false;
        }catch(BadLocationException e){
          e.getMessage();
          success_flag = false;
        /* Searches through all HREF attributes that are now stored in Vector
           vT for occurences of the character string ".htm" */
        sortStrings = new String[countX];
        for(int i=0;i<countX;i++)
          sortStrings[i] = (String)vT.elementAt(i); //Vector Strings transfered into array.
          if(sortStrings.endsWith("gif")) // Does href value end with ".jpg"?
    vS.addElement(sortStrings[i]); // If so add it to the sorted Vector vS.
    countY++;
    if(sortStrings[i].endsWith("GIF"))
    vS.addElement(sortStrings[i]);
    countY++;
    if(sortStrings[i].endsWith("jpg")) // Does href value end with ".jpg"?
    vS.addElement(sortStrings[i]); // If so add it to the sorted Vector vS.
    countY++;
    if(sortStrings[i].endsWith("JPG"))
    vS.addElement(sortStrings[i]);
    countY++;
    finalStrings = new String[countY];
    for(int j=0;j<countY;j++)
    finalStrings[j] = (String)vS.elementAt(j);
    /* What happens with these methods, will they need to have their
    own treads also? */
    public int getCount()
    return countY; //Returns number of instances of htm strings
    } //ending with either "jpg" or "gif".
    public String[] xurlAddressDetails()
    return finalStrings;
    Are there any special things that I need to do in regard to the variables returned by the getCount() and xurlAddressDetails() methods. These methods are called by the code that started the run method from within my GUI. I don't understand which thread these methods are running in, obviously there is an AWT thread for my GUI and then a seperate thread for my FullURLAddress objects, but does this new thread also encompass the getCount() and xurlAddressDetails() methods?
    Please explain.
    This probably sounds a little wack, but I don't understand what thread is responisble for the methods in my FullURLAddress class aside of course from the run() method which is obvious. Any help will be awesome.
    Thanks
    Davo

    Threads are part of code that allows you to run multiple operations "simultaneously". "Simultaneously", because threads are not run actually simultaneously in any one-CPU machine. Since you most propably have only one CPU in your system, you can only execute one CPU instruction at time. Basically this means that your CPU can handle only one java-operation at time. It does not matter if you put some code in thread and start it, it will still take up all CPU time as long as the thread runs.
    So you would need a way to let other threads run also, for that purpose thread contains a yield feature that allows you to give time for other threads to run.
    http://java.sun.com/j2se/1.4.1/docs/api/java/lang/Thread.html#yield()
    You need to use thread's yield() method in your thread code, in a place you want to give other threads time to run. Also bear in mind that if you yield your first thread run to allow second thread to run, you also need to add yield to the second thread also. If you don't, after yielding the first thread, the second thread will eat up all CPU time until it finishes, thus meaning the rest of your first thread will be run after second thread is done.
    One good place to execute yield() is usually at the end of a loop, for example 'for' or 'while' loop. This way you prevent for example while-deadlocks.
    Here is a java thread tutorial, worthy reading:
    http://java.sun.com/docs/books/tutorial/essential/threads/

Maybe you are looking for

  • Any opinions on if I should repair my old powerbook or just buy a new one?

    Alright, here's the situation. I have a Tipowerbook 867 (upgraded to 512 ram) that's a bit over two and a half years old. Over this two plus year period, I have used this powerbook quite a lot, pretty much every single day for several hours at a mini

  • Unable to Delete Folder, Could not find this item

    Currently, I'm having problem deleting an old Folder. Previously, I used its parent as a shared folder, but one day when I tried to clear that folder there is one folder that has duplicate. The problem is one of them (the old one) can't be deleted ev

  • Get MacBook air to factory specs

    I'm getting a new MacBook Air and want to give mine to a friend. How do I get it back to the way it was right out of box? Thanks

  • Link List Explorer NOT Opening In A New Window

    Hi All, I am trying to force my KM linklist links to open in a new window and this is proving to be a hard feat! I have navigated to System Admin --> System Config --> Knowledge Management --> Content Management --> Configuration --> Content Manageme

  • GW Mobility Service 2.0 : Questions on Postgresql

    Hello, Some questions about the new version. When I add a user, during the first synchronization, the status of the user specifies the state 11: What means? Where is the Postgresql field that indicates the version of ActivSync? Regards Olivier