This week's giveaway is in the EJB and other Java EE Technologies forum.
We're giving away four copies of EJB 3 in Action and have Debu Panda, Reza Rahman, Ryan Cuprak, and Michael Remijan on-line!
See this thread for details.
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 EJB 3 in Action this week in the EJB and other Java EE Technologies 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: 18108
    
  39

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
 
Similar Threads
Class Wide Lock..??
Thread
synchronized block
Concurrency Question with Thread.sleep(5000) ?
Thread's question