rupesh patil

Greenhorn
+ Follow
since Sep 14, 2009
Merit badge: grant badges
For More
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 rupesh patil

How the static method handels thread safty. As per the explaination read till this time like each thread has its own stack and memory allocated to it.
Even method has single copy of code

How in the following code Object of stringBuffer is actually maintained by java.
If there is single copy of code. When I am creating the instance of StringBuffer for every thread new instance of StringBuffer is get created but the reference variable is same.

How these tow reference copy of the variable is maintained.

Please any one can answer my querry....?


public class Running extends Thread {

String value;


public Running(String value){
this.value = value ;
}

public void run(){

callstaticMethod(this.value);
// System.out.println("value");
}

public static void callstaticMethod(String value){
StringBuffer object = new StringBuffer(value);
try {
Thread.sleep(5000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
object.append("2" + value);
System.out.println(object.toString());

}
public static void main(String[] args ){
Thread t1 = new Running("First");
Thread t2 = new Running("Second");

t1.start();
t2.start();

try {
t1.join();
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
try {
t2.join();
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

}
}

14 years ago