Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Threads

 
Vihanga Rajalingam
Greenhorn
Posts: 3
Android Java Mac PPC
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
class X{}
class Demo{
public static void main(String args[]){
final A a1=new A();

new Thread(){
public void run(){
synchronized(A.class){
a1.printName("Vihanga");
}
}
}.start();
//-----------------------

new Thread(){
public void run(){
a1.printAddress("Panadura");
}
}.start();
}
}
class A{
void printName(String name){
System.out.print("[");
try{Thread.sleep(1000);}catch(InterruptedException e){}
System.out.println(name+"]");
}
static synchronized void printAddress(String address){
System.out.print("{");
try{Thread.sleep(1000);}catch(InterruptedException e){}
System.out.println(address+"}");
}


I can't understand this program.

 
Henry Wong
author
Marshal
Pie
Posts: 20892
75
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Vihanga Rajalingam wrote:

I can't understand this program.



As already mentioned in your other topics, you have to help us help you. There are lots of concepts going on in this example, and we have no idea of what your knowledge is? Do you know threading? If so, how much? Do you know what an inner class is? Please read this...

https://www.coderanch.com/how-to/java/TellTheDetails

Also take a look at other tips here ... https://www.coderanch.com/how-to/java/HowToAskQuestionsOnJavaRanch

Henry
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic