• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

can thread access the non-synchronized method in a class when other thread hold lock

 
Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all,

I have a question regarding the synchronization of method..

can a thread access the non-synchronized method of an instance of class
when the other thread have the lock on the same instance of class?

because as i know the lock is for object ,
so if a class contains both synchronized and non synchronized methods , and if one thread has a lock on object(instance) , is that possible for other thread to call the non synchronized method using the same instance?

please explain it any one.......

Thanks,
vinay rajnish
 
Wanderer
Posts: 18671
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes. What further explanation is necessary? You've already got the idea. If a method is unsynchronized, then another thread can call it any time, with no special protection.
 
vianyrajnish rajnish
Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi ,

i am asking this because the non-synchronized method is in the same instance of the class , on which the other thread has the key(lock) with it.

can it be possible to access that non-synchronized method from other thread?

Thanks,
vinay rajnish
 
Jim Yingst
Wanderer
Posts: 18671
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes.
 
vianyrajnish rajnish
Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Jim Yungist,
That's cleard my doubt....
Thanks man!

Thanks,
vinay rajnish
 
Jim Yingst
Wanderer
Posts: 18671
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
No problem, Mr. Rajinush.
 
Ranch Hand
Posts: 1282
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by vianyrajnish rajnish:
....can it be possible to access that non-synchronized method from other thread? ....



The problem, if any, is keeping the data in in instance in a consistent state while two or more threads are active in the instance. I just went through a very convoluted discussion in which I figured all this Thread stuff out. Look at it this way:


It may seem odd, but on a multiple processor machine, the two threads can actually be at the same point at the same time. If that is the case, a variable on the left of the assignment operator can be changed by Thread_1 before Thread_2 can read it. Sounds incorrect, but on a Hydra with a theoretical peak performance of 4.8 Teraflops, total memory of 1.2 Terabytes, and a 21 Terabyte DDN disk array, keeping up with Who's on First can resemble Titanic in 30 seconds, re-enacted by bunnies.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic