Hey in working on a mini homework task in University and ive spent a while looking around online and through Api's to help me find a solution. the task is as follows:

The problem i have is that it should synchronize the Doors so that you can only access one, open that door then close it, Then have a 5000ms delay on the thread before the second door can be opened
I am struggling to get this synchronize working, mine just loops through printing out

2.3:Create the AirLock class
Create the AirLock class. For the purpose of this prototype this class can be empty of methods, instance variables and explicit constructors. It is just used to create a common object used by each of the threads.
that control the doors(used as part of the use of the synchronized keyword).

Task 2.4:
Create the Door class
Create the Door class. The Javadoc describes the required constructors and methods and their purpose and parameters. Make sure that you delay the opening of doors by about five seconds(5000 milliseconds) and use println
or format statements to simulate the opening of doors and show that two doors do not open at the same time. This is the class where threads run and access to the Airlock must be synchronized.
You will need to use some fields/instance variables; these are not described in the Javadoc.
These will be private. Consider whether any of these will need to be volatile.

Javadoc for the Door methods, this confuses me

public void run() Infinite loop used by the thread which checks whether a door open request has been made and then tries to get a key from the airlock in order to open the door. We simulate the opening of the door by using format statements and a 5 second sleep for the time it takes the door to open and then close again. The door open request is reset to false

Specified by:run in interface java.lang.Runnable

public void requestToOpen() This is rather like an RFID card read request for this door. We set the door open request flag to true NO IDEA WHAT THIS MEANS

My code so far

Java Code:
package uk.ac.aber.dcs.cs12420.spaceship.airlock;

 * Simulates astronauts trying to open spaceship airlock doors.
 * @author Chris Loftus (cwl@aber.ac.uk)

public class AstronautSimulator {

	private Door d;

	public static void main(String [] args){
		// Create an AirLock object
		Door[] doors = new Door[2];

		// For this prototype this can be an empty (no method)
		// class. It is a common object used in the Door class
		// that contains the single lock-key that protects the
		// imaginary airlock room from having two doors open at
		// the same time
		AirLock airLock = new AirLock();

		// Give the doors a name (for debugging purposes) and
		// a common airlock object used to store the "key" used
		// by a critical section of code in the Door class
		doors[0] = new Door("open", airLock);
		doors[1] = new Door("close", airLock);

		// Door implements Runnable and so make sure
		// we tie the objects to Thread objects
		Thread doorController1 = new Thread(doors[0]);
		Thread doorController2 = new Thread(doors[1]);


		while (true){
			// random() returns a value in range 0.0..<1.0 multiplied by 10 and mod doors.length
			// to return either 0 or 1 in order to randomly decide which door to request

			int door = (int)((Math.random() * 10) % doors.length);


			try {
				// Sleep for ~0.8 seconds before trying to open another door
			} catch (InterruptedException e) {}

Java Code:
package uk.ac.aber.dcs.cs12420.spaceship.airlock;

public class Door implements Runnable {

	private String name;
	private AirLock airlock;
	private volatile boolean open;

	public Door(String name, AirLock airlock) {
		this.name = name;
		this.airlock = airlock;


	public void run() {
			  System.out.println("Door :" + name + "Open");	
                          System.out.println("Door :" + name + "Closed");		

	public  synchronized void requestToOpen() {

This class below is meant to be "empty"

Java Code:

public class AirLock {
	public AirLock() {

My output is this in the console over and over, the thread doesnt not sleep this repeats like 100 times a second

Door :Door2 Closed
Door :Door2 Open
Door :Door2 Closed
Door :Door2 Open
Door :Door2 Closed
Door :Door2 Open
Door :Door2 Closed
Door :Door2 Open
Door :Door2 Closed