Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Java > Java and JDK > JSP Basics
|
JSP Basics Beginning-level questions on JSP. More advanced coders should post to Pro JSP.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the JSP Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old February 20th, 2007, 09:35 AM
Registered User
 
Join Date: Jan 2007
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default Method reffering to an object

HY


There is a problem , i have a method that takes as an argument a Thread object; and by all specs it should take it by refference not by value; but my method seems to do backwards; this is the method :

public void startThread (Thread e) {

        if(e == null) {

            e = new Thread(this);
            System.out.print(e+"\t\t"+t+"\n\n\n");

};
}


and for who wants the whole file here it is :


import javax.swing.*;

class updateThread
implements Runnable {

    Thread t,w;
    int s;
    boolean b;

    public updateThread(){};

    public static void main (String args[]) {

        updateThread obj = new updateThread();
        obj.startThread(obj.t);

        }

    public void startThread (Thread e) {

        if(e == null) {

            e = new Thread(this);
            System.out.print(e+"\t\t"+t+"\n\n\n");
        };
    }

    public void run() {

         try {
             while(true ) { s++;
                System.out.print("\n\n\n\n\t for s= "+s+"\n\t thread t "+ t+"\n\n\t thread w "+w);
                Thread.sleep(1000);
                if(s == 3) {stopThread();s=0;};
                }

            }
         catch(Exception e) { System.out.print("\n\n\n\t Exception "+e+"\n\n\n\n");};
}

    public void stopThread ( ) {

        if(true) {

            b = !b;

            if(!b) { w = t;
            t= null;}else{t = w; w = null;};
                    System.out.print("\n\n\n\n\t\t ****** thread change ********\n\n\n");

        }
    }

}

Ok ,so if u just watch closely at my method u see (after compilation)that e(pointing to obj.t) takes a value (from code : e = new Thread(this);) so ok but it does not affect t aswell; why? it should as it is passed by refference .

                     Thank u in advance.

 
Old March 23rd, 2007, 07:24 AM
Friend of Wrox
 
Join Date: Mar 2007
Posts: 373
Thanks: 0
Thanked 1 Time in 1 Post
Default

Hi,

You dont need to pass the t variable to the startThread() method, object t is available in startThread() method, you can just say

this.t = new Thread(this);

Regards,
Rakesh





Similar Threads
Thread Thread Starter Forum Replies Last Post
Object Rexx - Method Not Found ALFisher Other Programming Languages 0 September 7th, 2006 08:55 PM
How to call a method on a remote object eloyitomio C# 1 July 21st, 2006 10:17 AM
HtmlEncode method of Server object bekim C# 4 June 27th, 2004 01:38 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.