my dog learned polymorphism*
The moose likes Java in General and the fly likes Threads Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Threads" Watch "Threads" New topic
Author

Threads

Vihanga Rajalingam
Greenhorn

Joined: Aug 26, 2012
Posts: 3

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
Sheriff

Joined: Sep 28, 2004
Posts: 18914
    
  40

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


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Threads