Made corrections in Main

parent 9dc9f5c1
...@@ -2,13 +2,9 @@ ...@@ -2,13 +2,9 @@
<project version="4"> <project version="4">
<component name="ChangeListManager"> <component name="ChangeListManager">
<list default="true" id="a557173a-0c16-4d6f-82a4-07aa95bedc2f" name="Changes" comment=""> <list default="true" id="a557173a-0c16-4d6f-82a4-07aa95bedc2f" name="Changes" comment="">
<change afterPath="$PROJECT_DIR$/.gitignore" afterDir="false" /> <change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change afterPath="$PROJECT_DIR$/.idea/misc.xml" afterDir="false" /> <change beforePath="$PROJECT_DIR$/src/Main.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/Main.java" afterDir="false" />
<change afterPath="$PROJECT_DIR$/.idea/modules.xml" afterDir="false" /> <change beforePath="$PROJECT_DIR$/src/MyThread.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/MyThread.java" afterDir="false" />
<change afterPath="$PROJECT_DIR$/.idea/uiDesigner.xml" afterDir="false" />
<change afterPath="$PROJECT_DIR$/.idea/vcs.xml" afterDir="false" />
<change afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change afterPath="$PROJECT_DIR$/Assignment_5.iml" afterDir="false" />
</list> </list>
<option name="SHOW_DIALOG" value="false" /> <option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" /> <option name="HIGHLIGHT_CONFLICTS" value="true" />
...@@ -34,13 +30,13 @@ ...@@ -34,13 +30,13 @@
<option name="hideEmptyMiddlePackages" value="true" /> <option name="hideEmptyMiddlePackages" value="true" />
<option name="showLibraryContents" value="true" /> <option name="showLibraryContents" value="true" />
</component> </component>
<component name="PropertiesComponent"><![CDATA[{ <component name="PropertiesComponent">{
"keyToString": { &quot;keyToString&quot;: {
"RunOnceActivity.OpenProjectViewOnStart": "true", &quot;RunOnceActivity.OpenProjectViewOnStart&quot;: &quot;true&quot;,
"RunOnceActivity.ShowReadmeOnStart": "true", &quot;RunOnceActivity.ShowReadmeOnStart&quot;: &quot;true&quot;,
"SHARE_PROJECT_CONFIGURATION_FILES": "true" &quot;SHARE_PROJECT_CONFIGURATION_FILES&quot;: &quot;true&quot;
} }
}]]></component> }</component>
<component name="RunManager" selected="Application.Main"> <component name="RunManager" selected="Application.Main">
<configuration name="Main" type="Application" factoryName="Application" temporary="true" nameIsGenerated="true"> <configuration name="Main" type="Application" factoryName="Application" temporary="true" nameIsGenerated="true">
<option name="MAIN_CLASS_NAME" value="Main" /> <option name="MAIN_CLASS_NAME" value="Main" />
......
public class Main { public class Main {
public static void main(String[] args) { public static void main(String[] args) throws InterruptedException {
for(int i = 1; i <=2; i++) {
MyThread t1 = new MyThread("Thread " + i); System.out.println("Main thread begins");
t1.start(); MyThread t1 = new MyThread("Thread1");
try { MyThread t2 = new MyThread("Thread2");
t1.sleep(1000); t1.start();
} catch (Exception e) { t2.start();
System.out.println("exception"); t1.join();
} t2.join();
}
System.out.println("Main thread ends"); System.out.println("Main thread ends");
} }
} }
...@@ -4,13 +4,17 @@ public class MyThread extends Thread { ...@@ -4,13 +4,17 @@ public class MyThread extends Thread {
this.threadName = threadName; this.threadName = threadName;
} }
public void run() { public void run() {
try { for (int i = 0; i < 5; i++) {
System.out.println("Thread: " + Thread.currentThread().getName() + " is running");
} System.out.println(Thread.currentThread().getName() + " is running: " + i);
catch (Exception ex) {
System.out.println("exception"); try {
} sleep(1000);
} catch (Exception ex) {
System.out.println("exception");
}
}
} }
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment