Understanding ReentrantLocks and Thread basics
<p>I am trying to write a basic program using threads. Assuming I have two threads, t1 and t2 and lock x. Assuming lock x is assigned to t1. When would be a situation where t2 would be unable to process due to lock x being assigned to t1? I am trying to create a simple example to demonstrate how locks/threads work.</p>

<p>I appreciate any assistance in this matter. </p>

<p>This is what I got so far:</p>

<p>Class Skywalker:</p>

<pre><code>import java.util.*;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

public class Skywalker{
    public static void main(String args[]){
        Thread t1 = new Thread("station 1");
        Thread t2 = new Thread("station 2");

        t1.start();
        t2.start();
    }
}
</code></pre>

<p>Class Darth:    </p>

<pre><code>import java.util.Random;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

public class Darth implements Runnable{
    String stationName;
    Lock x = new ReentrantLock();
    Random r = new Random();

    public Darth(String name){
        stationName = name;
    }

    public void run(){
        try{
            x.lock();
            System.out.println(stationName + "is working");
            sleep(randomTime);
            x.unlock();

        } catch(Exception e) {
        }
    }
}
</code></pre>
