changeset 9:e6ea4e10df98

move files as gradle project
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Fri, 23 Sep 2016 12:12:55 +0900
parents 9ee04de7718a
children 272cfe639e2f
files src/deadLockTest/Client.java src/deadLockTest/Server.java src/deadLockTest/TestDeadLock.java src/main/java/deadLockTest/Client.java src/main/java/deadLockTest/Server.java src/main/java/deadLockTest/TestDeadLock.java src/main/java/threadTest/Client.java src/main/java/threadTest/Hello.java src/main/java/threadTest/Server.java src/main/java/threadTest/TestThread.java src/threadTest/Client.java src/threadTest/Hello.java src/threadTest/Server.java src/threadTest/TestThread.java
diffstat 14 files changed, 171 insertions(+), 171 deletions(-) [+]
line wrap: on
line diff
--- a/src/deadLockTest/Client.java	Fri Sep 23 11:59:50 2016 +0900
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,27 +0,0 @@
-package deadLockTest;
-
-public class Client extends Thread {
-	Server server1;
-	Server server2;
-	String name;
-	
-	Client(String name, Server hotel, Server plane) {
-		this.server1 = hotel;
-		this.server2 = plane;
-		this.name = name;
-	}
-	
-	public void run() {
-		try {
-			server1.lock(name);
-			server2.lock(name);
-			server1.reserve(name);
-			server2.reserve(name);
-			server1.release(name);
-			server2.release(name);
-		} catch (InterruptedException e) {
-			System.out.println(name + " Error occured.");
-		}
-		System.out.println(name + "Reserve conmpleted.");
-	}
-}
--- a/src/deadLockTest/Server.java	Fri Sep 23 11:59:50 2016 +0900
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,32 +0,0 @@
-package deadLockTest;
-
-public class Server {
-	int count = 0;
-	private boolean lock;
-	private String sname;
-	
-	public Server(String name) {
-		this.sname = name;
-	}
-
-	synchronized void reserve(String name) {
-		System.err.println(name + " server-enter "+sname+" : count="+count);
-		count++;
-		System.err.println(name + " server-leave "+sname+" : count="+count);
-	}
-
-	public synchronized void lock(String name) throws InterruptedException {
-		while (lock) {
-			System.err.println(name + " is wating "+sname);
-			wait();
-		}
-		lock = true;
-		System.err.println(name + " gets lock "+ sname);	
-	}
-
-	public synchronized void release(String name) {
-		System.err.println(name + " releases lock "+sname);	
-		lock = false;
-		notify();
-	}
-}
--- a/src/deadLockTest/TestDeadLock.java	Fri Sep 23 11:59:50 2016 +0900
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,25 +0,0 @@
-package deadLockTest;
-
-public class TestDeadLock {
-	Server hotel = new Server("Hilton");
-	Server plane = new Server("JAL");
-	Client t2 = new Client("Steve", plane,hotel);
-	Client t3 = new Client("Tedd", plane,hotel);
-	
-	public static void main(String arg[]) throws InterruptedException  {
-		TestDeadLock test = new TestDeadLock();
-		test.test();
-	}
-	
-	public void test() throws InterruptedException {
-		t2.start();
-		t3.start();
-		t2.join();
-		t3.join();
-
-		System.err.println(
-				"Plane = "+plane.count+
-				" Hotel = "+hotel.count);
-	}
-
-}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/main/java/deadLockTest/Client.java	Fri Sep 23 12:12:55 2016 +0900
@@ -0,0 +1,27 @@
+package deadLockTest;
+
+public class Client extends Thread {
+	Server server1;
+	Server server2;
+	String name;
+	
+	Client(String name, Server hotel, Server plane) {
+		this.server1 = hotel;
+		this.server2 = plane;
+		this.name = name;
+	}
+	
+	public void run() {
+		try {
+			server1.lock(name);
+			server2.lock(name);
+			server1.reserve(name);
+			server2.reserve(name);
+			server1.release(name);
+			server2.release(name);
+		} catch (InterruptedException e) {
+			System.out.println(name + " Error occured.");
+		}
+		System.out.println(name + "Reserve conmpleted.");
+	}
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/main/java/deadLockTest/Server.java	Fri Sep 23 12:12:55 2016 +0900
@@ -0,0 +1,32 @@
+package deadLockTest;
+
+public class Server {
+	int count = 0;
+	private boolean lock;
+	private String sname;
+	
+	public Server(String name) {
+		this.sname = name;
+	}
+
+	synchronized void reserve(String name) {
+		System.err.println(name + " server-enter "+sname+" : count="+count);
+		count++;
+		System.err.println(name + " server-leave "+sname+" : count="+count);
+	}
+
+	public synchronized void lock(String name) throws InterruptedException {
+		while (lock) {
+			System.err.println(name + " is wating "+sname);
+			wait();
+		}
+		lock = true;
+		System.err.println(name + " gets lock "+ sname);	
+	}
+
+	public synchronized void release(String name) {
+		System.err.println(name + " releases lock "+sname);	
+		lock = false;
+		notify();
+	}
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/main/java/deadLockTest/TestDeadLock.java	Fri Sep 23 12:12:55 2016 +0900
@@ -0,0 +1,25 @@
+package deadLockTest;
+
+public class TestDeadLock {
+	Server hotel = new Server("Hilton");
+	Server plane = new Server("JAL");
+	Client t2 = new Client("Steve", plane,hotel);
+	Client t3 = new Client("Tedd", hotel,plane);
+	
+	public static void main(String arg[]) throws InterruptedException  {
+		TestDeadLock test = new TestDeadLock();
+		test.test();
+	}
+	
+	public void test() throws InterruptedException {
+		t2.start();
+		t3.start();
+		t2.join();
+		t3.join();
+
+		System.err.println(
+				"Plane = "+plane.count+
+				" Hotel = "+hotel.count);
+	}
+
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/main/java/threadTest/Client.java	Fri Sep 23 12:12:55 2016 +0900
@@ -0,0 +1,13 @@
+package threadTest;
+
+public class Client extends Thread {
+	Server server;
+	
+	Client(Server s) {
+		this.server = s;
+	}
+	
+	public void run() {
+	    server.work();
+	}
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/main/java/threadTest/Hello.java	Fri Sep 23 12:12:55 2016 +0900
@@ -0,0 +1,7 @@
+package threadTest;
+
+public class Hello {
+	public static void main(String arg[]) {
+		System.out.println("hello");
+	}
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/main/java/threadTest/Server.java	Fri Sep 23 12:12:55 2016 +0900
@@ -0,0 +1,41 @@
+package threadTest;
+
+public class Server {
+	int count = 0;
+
+	void work()  {
+		//System.err.println("server-enter: count="+count);
+		count ++;
+		//System.err.println("server-leave: count="+count);
+	}
+	
+	void slow_work()  {
+		int tmp;
+		tmp = count ;
+		sloop();
+		//System.err.println("server-enter: count="+count);
+		tmp ++;
+		sloop();
+		count = tmp ;
+		//System.err.println("server-leave: count="+count);
+	}
+
+    private void sloop()  {
+        try {
+            Thread.sleep(0);
+        } catch (InterruptedException e) {
+            e.printStackTrace();
+        }
+    }
+	
+	synchronized void sync_work()  {
+		int tmp;
+		tmp = count ;
+		//Thread.sleep(500);
+		//System.err.println("server-enter: count="+count);
+		tmp ++;
+		//Thread.sleep(500);
+		count = tmp ;
+		//System.err.println("server-leave: count="+count);
+	}
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/main/java/threadTest/TestThread.java	Fri Sep 23 12:12:55 2016 +0900
@@ -0,0 +1,26 @@
+package threadTest;
+
+public class TestThread {
+	Server t1 = new Server();
+	Client t2 = new Client(t1);
+	Client t3 = new Client(t1);
+
+	public static void main(String arg[]) throws InterruptedException  {
+		//for(int i = 0; i<10000;i++) {
+			TestThread test = new TestThread();
+			test.test();
+		//}
+	}
+	
+	public void test() throws InterruptedException {
+		t2.start();
+		t3.start();
+		t2.join();
+		t3.join();
+
+		if (t1.count!=2)
+			System.err.println("testThread: count = "+t1.count);
+		assert(t1.count==2);
+	}
+
+}
--- a/src/threadTest/Client.java	Fri Sep 23 11:59:50 2016 +0900
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,13 +0,0 @@
-package threadTest;
-
-public class Client extends Thread {
-	Server server;
-	
-	Client(Server s) {
-		this.server = s;
-	}
-	
-	public void run() {
-	    server.work();
-	}
-}
--- a/src/threadTest/Hello.java	Fri Sep 23 11:59:50 2016 +0900
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,7 +0,0 @@
-package threadTest;
-
-public class Hello {
-	public static void main(String arg[]) {
-		System.out.println("hello");
-	}
-}
--- a/src/threadTest/Server.java	Fri Sep 23 11:59:50 2016 +0900
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,41 +0,0 @@
-package threadTest;
-
-public class Server {
-	int count = 0;
-
-	void work()  {
-		//System.err.println("server-enter: count="+count);
-		count ++;
-		//System.err.println("server-leave: count="+count);
-	}
-	
-	void slow_work()  {
-		int tmp;
-		tmp = count ;
-		sloop();
-		//System.err.println("server-enter: count="+count);
-		tmp ++;
-		sloop();
-		count = tmp ;
-		//System.err.println("server-leave: count="+count);
-	}
-
-    private void sloop()  {
-        try {
-            Thread.sleep(0);
-        } catch (InterruptedException e) {
-            e.printStackTrace();
-        }
-    }
-	
-	synchronized void sync_work()  {
-		int tmp;
-		tmp = count ;
-		//Thread.sleep(500);
-		//System.err.println("server-enter: count="+count);
-		tmp ++;
-		//Thread.sleep(500);
-		count = tmp ;
-		//System.err.println("server-leave: count="+count);
-	}
-}
--- a/src/threadTest/TestThread.java	Fri Sep 23 11:59:50 2016 +0900
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,26 +0,0 @@
-package threadTest;
-
-public class TestThread {
-	Server t1 = new Server();
-	Client t2 = new Client(t1);
-	Client t3 = new Client(t1);
-
-	public static void main(String arg[]) throws InterruptedException  {
-		//for(int i = 0; i<10000;i++) {
-			TestThread test = new TestThread();
-			test.test();
-		//}
-	}
-	
-	public void test() throws InterruptedException {
-		t2.start();
-		t3.start();
-		t2.join();
-		t3.join();
-
-		if (t1.count!=2)
-			System.err.println("testThread: count = "+t1.count);
-		assert(t1.count==2);
-	}
-
-}