usama akhtar

Greenhorn
+ Follow
since Jun 08, 2001
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by usama akhtar

Try the following code. It should solve your problem.

public class Tux1 extends Thread
{
static String sName = "vandeleur";
public static void main(String argv[])
{
Tux1 t = new Tux1();
t.piggy(sName);
System.out.println(sName);
}

public void piggy(String sName)
{
sName = sName + " wiggy";
setPriority(10);
start();
}

public void run()
{
for(int i=0;i < 4; i++)
{
for(int j=0;j < 4; j++)
{
sName = sName + " " + i +j;
}
}
}
}
In this modified version of your program we are setting the thread priority of the child thread to be greater that that of the main thread. This ensures that the child thread executes before the main one. So when the main thread is executed, it prints out the value of sName which has already been modified by the child thread.
Hope this helped and correct me if I'm wrong.