Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / June 2007

Tip: Looking for answers? Try searching our database.

Thread Synchronization

Thread view: 
sachin - 05 Jun 2007 10:25 GMT
Hi everyone,
I have following code ::

case 1:
public class Resource {
                                   public synchronized void met1()
{ }
                                   public void met2() { }
                               }
And three threads t1,t2,t3.If thread t1 is using met1() can other
threads t2 ,t3 can use met2() at same time ??

case 2:
Also if the met1() is changed to
                                                     public static
synchronized void met1() {  }
Can t2,t3 access met2() if t1 is using met1() at same time?
Ingo R. Homann - 05 Jun 2007 10:41 GMT
Hi,

> Hi everyone,
> I have following code ::
[quoted text clipped - 7 lines]
> And three threads t1,t2,t3.If thread t1 is using met1() can other
> threads t2 ,t3 can use met2() at same time ??

Yes.

> case 2:
> Also if the met1() is changed to
>                                                       public static
> synchronized void met1() {  }
> Can t2,t3 access met2() if t1 is using met1() at same time?

Yes.

Please read a book!

Ciao,
Ingo
Tom Hawtin - 05 Jun 2007 11:39 GMT
> public class Resource {
>                                     public synchronized void met1()
[quoted text clipped - 3 lines]
> And three threads t1,t2,t3.If thread t1 is using met1() can other
> threads t2 ,t3 can use met2() at same time ??

The key concept is that

    synchronized void fn() {
        ...
    }

is just a short form of

    void fn() {
        synchronized (this) {
            ...
        }
    }

You just need to keep your eye on which instance you are synchronising on.

Tom Hawtin


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.