Java locking in one thread, unlocking in another
<p>I need to lock class objects (which handles a socket connection) and pass those objects to threads for processing.</p>

<pre><code>public class Client{

    protected Socket socket;
    ...
    public Lock lock = new ReentrantLock();

}
</code></pre>

<p>I have a simple worker class that handles the work.</p>

<pre><code>public class ClientWriterWorker extends Runnable{

    protected Client client;
    protected String data;

    public ClientWriterWorker(Client client, String data){
        this.client = client;
        this.data = data;
    }

    @Override
    public void run(){
        // do the processing
        this.client.write(this.data);
        // release the lock?
        this.client.lock.unlock(); // does not work
    }

}
</code></pre>

<p>Then I have a loop that gets unlocked client, locks it, and passes it to thread.</p>

<pre><code>Client currentClient = null;
while(true){
    for(Client client : clients){
        if(client.lock.tryLock()){
             // we have the lock
             currentClient = client;
             break;
        }
    }
    if(currentClient != null){
        break;
    }
}
new Thread(new ClientWriterWorker(currentClient, "some data")).start();
</code></pre>

<p>Is it possible to unlock locks in another thread? Is my design flawed?</p>