• 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

threads synchronization

 
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
how will the following code execute..

class demo extends Thread{
static Object lock = new Object();
static Object lock = new Object();
int i,j,k;
demo()
{
start();
}
public void run()
{
doit();
check();
}
doit()
{
synchronized(lock1)
{
i++;
}
synchronized(lock2)
{
j++;
}
synchronized(lock1)
{
k++;
}
}
check()
{
}
public void main(String args[])
{
demo d = new demo();
}
my problem is will the code sync(lock2 ) for lock 1 will be bypassed or what will happen???
 
Ranch Hand
Posts: 439
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
first you'll get exception saying that the lock is already defined.
 
pooja agrawal
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
sorry it was a typing mistake it's lock1 and lock2.
 
Ranch Hand
Posts: 159
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
pooja ,
whatz u r doubt why will it bypass
or is there anymore typing mistakes like nested snchronisation
Cherry
 
reply
    Bookmark Topic Watch Topic
  • New Topic