Commits

Nick Raptis committed b8b5284

Missed a file on last commit

  • Participants
  • Parent commits 6b08a24

Comments (0)

Files changed (1)

File src/Lab07/Crane.java

+package Lab07;
+
+import Lab04v3.*;
+
+/**
+ * This is a Crane that will load containers to our ship
+ * running in a parallel thread.
+ * @author Nick Raptis <airscorp@gmail.com>
+ */
+public class Crane extends Thread {
+    Ship s;
+
+    public Crane(String name, Ship s) {
+        super(name);
+        this.s = s;
+    }
+
+    public Ship getS() {
+        return s;
+    }
+
+    public void setS(Ship s) {
+        this.s = s;
+    }
+
+    public void run()
+    {
+        boolean success;
+        while(true)
+        { try
+         {
+            //Make a new object
+            OrthContainer p = new OrthContainer(10, 10, 10);
+            //Load
+            synchronized (s) {
+                success = s.load(p);
+            }
+
+            //Notify user
+            if (success)
+                System.out.println("Crane "+getName()+" loaded a container");
+            else
+                System.out.println("Crane "+getName()+" nothing more to do");
+
+            // End the thread if unable to load any more containers
+            if (!success)
+                stop();
+
+            sleep(2000);
+
+         } catch (InterruptedException ex)
+         {
+            stop();
+         }
+        }
+    }
+
+}