Query:lock by virtual object!

J

Jack Dowson

Hello Everybody:
I saw a demo as follow shows how to use virtual object to lock key
resources in order to maintain synchronizing if there are several threads.

class ClassName implements Runnable{
String str = " ";
public void run(){
...
synchronized(str){...}
}
}

I just can't understand how it works?

Any help will be greatly appreciated!

Dowson!
 
J

Jack Dowson

Jack Dowson дµÀ:
Hello Everybody:
I saw a demo as follow shows how to use virtual object to lock key
resources in order to maintain synchronizing if there are several threads.

class ClassName implements Runnable{
String str = " ";
public void run(){
...
synchronized(str){...}
}
}

I just can't understand how it works?

Any help will be greatly appreciated!

Dowson!
This question is really stupid!

Dowson!
 
Z

Z.

Jack said:
Hello Everybody:
I saw a demo as follow shows how to use virtual object to lock key
resources in order to maintain synchronizing if there are several threads.

class ClassName implements Runnable{
String str = " ";
public void run(){
...
synchronized(str){...}
}
}

I just can't understand how it works?

Any help will be greatly appreciated!

Dowson!

http://java.sun.com/docs/books/tutorial/essential/concurrency/index.html,
also:
http://java.sun.com/docs/books/tutorial/essential/concurrency/syncmeth.html
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,774
Messages
2,569,599
Members
45,175
Latest member
Vinay Kumar_ Nevatia
Top