• 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

logic for lock

 
Ranch Hand
Posts: 125
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
someone please check my lock logic and let me know if there are any flaws.
boolean lock=true;
public void lock(num) {
synchronized(vector) {
if( (vector.containsKey(new Integer(num))) ||
(vector.containsKey(new Integer(-1))) ||
(! lock)) {
try {
vector.wait();
} catch(InterruptedException ie) {
}
while (lock) {
while((vector.size() > 0) & (num == -1)) {
lock = false;
try {
vector.wait();
} catch(InterruptedException ie) {
}
vector.put(new Integer(num), "true");
//notifyAll();
break;
}
}
}
}
}
 
Ranch Hand
Posts: 273
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Looks good to me expect on thing. Vector holds your list of of lock right! If so, use other data structure instead of Vector. Vector is synchronized. You are putting synchronized object in synchronized block.
-Bal
 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi there,
I was looking at many lock/unlock designs discussion in this forum and still couldn't find a way to pass in clientID when calling lock. I have a similar as yours but there is no notion of clientID. If I have something like:
public class ServerImpl extends UnicastRemoteObject implements IServer
{
public void reserveSeat( clientID, flightID, numSeats )....
{
lock(recordNo);
read(...);
modify(....);
unlock(recordNo);
}
}
public class DataExt extends Data
{
public void lock(int record)...
{
}
}
Can you give me some pointers on how to pass clientID to DataExt?
Thanks in advance,
Brandon
 
Reshma Das
Ranch Hand
Posts: 125
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
pass it thru an additional constructor.
or u want a soln for getting unique client id ( ip addr) or something ?
 
reply
    Bookmark Topic Watch Topic
  • New Topic