Win a copy of Testing JavaScript Applications this week in the HTML Pages with CSS and JavaScript forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

syncronized ticketBooking method

 
Ranch Hand
Posts: 133
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My ticketBooking method on server is like this:

public String book(int rec, int tickets)throws DatabaseException{
DataInfo info=null;
String msg=null;
try{
if(rec==-1)
{
lock(rec);
msg="Database locked";
}
else
{
lock(rec);
System.out.println("Record "+rec+ " locked");
info=getRecord(rec);
String [] val = info.getValues();
int currentSeats=Integer.parseInt(val[val.length-1]);
if(currentSeats<=0)
{
msg="Sorry no seats left";
unlock(rec);
}
else
{
val[val.length-1]=String.valueOf(currentSeats - tickets);
modify(new DataInfo(rec, getFieldInfo(), val));
unlock(rec);
System.out.println("Record "+rec+ " unlocked");
}
}
}
catch(IOException ex){
throw new IllegalMonitorStateException("Database Locked "+ ex);
}
return msg;
}
Is This the right approach..
One problem i am getting when I include syncronized keyword on ticketBooking method and from the client side when i click seat book button the whole application Hangs and no furthur transactions can be carried on, But by removing the the Sync. keyword It works fine and displays message "Database Locked" on each client when database is locked. I want to know that why i am getting this problem. Waiting for valid response from you Guys.
Anurag Mishra
 
Anurag Mishra
Ranch Hand
Posts: 133
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Come On Guys
Help Me Out !!
Please some valid responses required immediately.
Anurag Mishra
 
Thanks tiny ad, for helping me escape the terrible comfort of this chair.
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
    Bookmark Topic Watch Topic
  • New Topic