• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

syncronized ticketBooking method

 
Anurag Mishra
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic