java - How to acquire lock on a RMI method -


i'm new rmi (should) know how use locks, , frankly not quite whole rmi thing, i'm not sure concept i'm missing code not blocked.

it's been while since did concurrency, afaik, this:

if (condition) {     write.lock();     //do since it's inside critical section     write.unlock(); } 

and on. , don't need reentrantreadwritelocks or whatever, need method lock , free it. need free lock in method, , stop understanding need (when it's code rmi methods , clients , servers , i'm doing).

what i've got far:

public synchronized void acquire (boolean exc) throws remoteexception {     if (exc) {         write.lock();     else {         read.lock();         exclusivo = exc;     } }  public synchronized boolean setfree() throws remoteexception {     if (read.trylock()) {         read.unlock();     } else {         return false;     } } 

and client invokes 1 method lock, makes operations, , uses other method free it. not finished, , believe (though i'm not sure, , that's why i'm asking), read lock done right... have trouble "believing" it, though i've tried , seems work, i'm not sure if i'm missing else.

that's 1 problem, other is, don't know write lock, since if write.trylock, , it's free, it's going lock, , i'd... free , return true guess? time condition returned, lock used again, since it's write lock? that, not sure


Comments

Popular posts from this blog

node.js - Using Node without global install -

How to access a php class file from PHPFox framework into javascript code written in simple HTML file? -

java - Null response to php query in android, even though php works properly -