{"action":"created","issue":{"url":"https://api.github.com/repos/STIW3054-A181/Main-Issues/issues/12","repository_url":"https://api.github.com/repos/STIW3054-A181/Main-Issues","labels_url":"https://api.github.com/repos/STIW3054-A181/Main-Issues/issues/12/labels{/name}","comments_url":"https://api.github.com/repos/STIW3054-A181/Main-Issues/issues/12/comments","events_url":"https://api.github.com/repos/STIW3054-A181/Main-Issues/issues/12/events","html_url":"https://github.com/STIW3054-A181/Main-Issues/issues/12","id":376230372,"node_id":"MDU6SXNzdWUzNzYyMzAzNzI=","number":12,"title":"Week07-01","user":{"login":"zhamri","id":24503750,"node_id":"MDQ6VXNlcjI0NTAzNzUw","avatar_url":"https://avatars3.githubusercontent.com/u/24503750?v=4","gravatar_id":"","url":"https://api.github.com/users/zhamri","html_url":"https://github.com/zhamri","followers_url":"https://api.github.com/users/zhamri/followers","following_url":"https://api.github.com/users/zhamri/following{/other_user}","gists_url":"https://api.github.com/users/zhamri/gists{/gist_id}","starred_url":"https://api.github.com/users/zhamri/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/zhamri/subscriptions","organizations_url":"https://api.github.com/users/zhamri/orgs","repos_url":"https://api.github.com/users/zhamri/repos","events_url":"https://api.github.com/users/zhamri/events{/privacy}","received_events_url":"https://api.github.com/users/zhamri/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":19,"created_at":"2018-11-01T02:35:25Z","updated_at":"2018-11-04T15:36:32Z","closed_at":null,"author_association":"CONTRIBUTOR","body":"## Instruction:\r\n\r\nWrite a Java program based on the following specifications:\r\n\r\n1. Create class A by implementing Runnable.\r\n2. Create class B that extends Thread.\r\n3. A method in class A will be locked until the lock is released by a method in class B. \r\n\r\n(You may choose any case studies from the website)"},"comment":{"url":"https://api.github.com/repos/STIW3054-A181/Main-Issues/issues/comments/435679564","html_url":"https://github.com/STIW3054-A181/Main-Issues/issues/12#issuecomment-435679564","issue_url":"https://api.github.com/repos/STIW3054-A181/Main-Issues/issues/12","id":435679564,"node_id":"MDEyOklzc3VlQ29tbWVudDQzNTY3OTU2NA==","user":{"login":"AiniArasad","id":33992233,"node_id":"MDQ6VXNlcjMzOTkyMjMz","avatar_url":"https://avatars2.githubusercontent.com/u/33992233?v=4","gravatar_id":"","url":"https://api.github.com/users/AiniArasad","html_url":"https://github.com/AiniArasad","followers_url":"https://api.github.com/users/AiniArasad/followers","following_url":"https://api.github.com/users/AiniArasad/following{/other_user}","gists_url":"https://api.github.com/users/AiniArasad/gists{/gist_id}","starred_url":"https://api.github.com/users/AiniArasad/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/AiniArasad/subscriptions","organizations_url":"https://api.github.com/users/AiniArasad/orgs","repos_url":"https://api.github.com/users/AiniArasad/repos","events_url":"https://api.github.com/users/AiniArasad/events{/privacy}","received_events_url":"https://api.github.com/users/AiniArasad/received_events","type":"User","site_admin":false},"created_at":"2018-11-04T15:36:32Z","updated_at":"2018-11-04T15:36:32Z","author_association":"NONE","body":"**Class A**\r\n```java\r\nimport java.util.concurrent.locks.Lock;\r\nimport java.util.concurrent.locks.ReentrantLock;\r\n\r\n    public class ClassA  implements Runnable {\r\n\r\n        private final Lock lock = new ReentrantLock();\r\n\r\n        @Override\r\n        public void run() {\r\n\r\n            try {\r\n                lock.lock();\r\n                \r\n                System.out.println(\"\\nClass A\");\r\n                for (int i = 1; i <= 10; i++) {\r\n                    System.out.println(i);\r\n                }\r\n            } catch (Exception e) {\r\n\r\n            }\r\n        }\r\n    }\r\n``` \r\n**Class B**\r\n```java\r\nimport java.util.concurrent.locks.Lock;\r\nimport java.util.concurrent.locks.ReadWriteLock;\r\nimport java.util.concurrent.locks.ReentrantLock;\r\n\r\n    public class ClassB extends Thread{\r\n        \r\n            private final Lock lock = new ReentrantLock();\r\n\r\n            @Override\r\n            public void run() {\r\n\r\n\r\n                Runnable runnable = new ClassA();\r\n                Thread thread = new Thread(runnable);\r\n                thread.start();\r\n\r\n                try {\r\n                    lock.unlock();\r\n                } catch (Exception e) {\r\n\r\n                    try {\r\n                        lock.lock();\r\n                        System.out.println(\"\\nClass B\");\r\n                        for (int a = 11; a <=15; a++) {\r\n                            //System.out.println(\"\\nClass B\");\r\n                            //System.out.print(\"b\" + a + \"\\t\");\r\n                            System.out.println(a);\r\n                        }\r\n                    } finally {\r\n                        lock.unlock();\r\n                    }\r\n\r\n                }\r\n            }\r\n        }\r\n```\r\n**Main Class**\r\n```java\r\npublic class Main {\r\n\r\n    public static void main (String[] args){\r\n\r\n        ClassB classB = new ClassB();\r\n\r\n        classB.start();\r\n    }\r\n}\r\n```\r\n![image](https://user-images.githubusercontent.com/33992233/47966170-663a3700-e08a-11e8-8aff-eb8a8c56f373.png)\r\n\r\n\r\n\r\n\r\n\r\n"}}
{"actor":{"display_login":"AiniArasad"}}