The Artima Developer Community
Sponsored Link

Legacy Java Answers Forum
August 2000

Advertisement

Advertisement

This page contains an archived post to the Java Answers Forum made prior to February 25, 2002. If you wish to participate in discussions, please visit the new Artima Forums.

Message:

Threads and sharing code/data

Posted by Raees Uzhunnan on August 10, 2000 at 12:37 PM


Hi ,

I need help on this code . Need to know whether this code generates
ambiguous results. Really don't know how threads work . if you can
explain me , will be great !!

//Code here
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

class JustAMethod
{
public int doCalculation(int seed)
{
int temp ;
/* do some complex calculations
/
/
/
/
/
/like
/////////////////////////////*/
temp = seed* 1000;
return temp;
}
}


class MyThread extends Thread
{
int iSeed;
MyThread(int seed )
{
iSeed = seed ;
start() ; // thread to start
}

public void run ()
{
int temp ;
JustAMethod jm = new JustAMethod();
while( true)
{
temp = jm.doCalculation(iSeed);
System.out.println("Result of calulation @ this point with seed " +
iSeed + "is " + temp);
}
}
}

public class CodeDataSegment
{
public static void main ( String [] args )
{
MyThread m = new MyThread( 10 );
MyThread m2 = new MyThread( 20 );
}
}

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

if you are busy , please forward to somebody , who can explain me this

Thanks

RaeesUzhunnan
ruzhunnan@fedex.com






Replies:

Sponsored Links



Google
  Web Artima.com   
Copyright © 1996-2009 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use - Advertise with Us