Skip to content

Commit

Permalink
Set Up For Threading
Browse files Browse the repository at this point in the history
  • Loading branch information
binayag1 committed Jun 13, 2018
0 parents commit 551bbc1
Show file tree
Hide file tree
Showing 13 changed files with 180 additions and 0 deletions.
26 changes: 26 additions & 0 deletions .classpath
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" output="target/classes" path="src/main/java">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" output="target/test-classes" path="src/test/java">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="output" path="target/classes"/>
</classpath>
23 changes: 23 additions & 0 deletions .project
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>MultiThreading</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.m2e.core.maven2Builder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
<nature>org.eclipse.m2e.core.maven2Nature</nature>
</natures>
</projectDescription>
4 changes: 4 additions & 0 deletions .settings/org.eclipse.core.resources.prefs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
eclipse.preferences.version=1
encoding//src/main/java=UTF-8
encoding//src/test/java=UTF-8
encoding/<project>=UTF-8
5 changes: 5 additions & 0 deletions .settings/org.eclipse.jdt.core.prefs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5
org.eclipse.jdt.core.compiler.compliance=1.5
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
org.eclipse.jdt.core.compiler.source=1.5
4 changes: 4 additions & 0 deletions .settings/org.eclipse.m2e.core.prefs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
activeProfiles=
eclipse.preferences.version=1
resolveWorkspaceProjects=true
version=1
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# MultiThreadinInJava
This project covers the concept about MultiThreading in Java.

# IDE used
Version: Oxygen.3a Release (4.7.3a)
Build id: 20180405-1200

# In this Commit:
There are three classes named App, B and C. In class B and C, a method is written which display the message five times. To understand how thread can work, Thread.sleep() has been used. Which delays the execution of thread by 1000 millisecond. We can have the look of how thred gets executed. In class App, object of B and C has been created. Eventually, method are called. The process of execution will be in sequential order which mean first printMessage() of class B will executed 5 times and printMessage() of class C will be executed 5 times. But during the execution each loop execution is delayed by 1 second.
25 changes: 25 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>binaya</groupId>
<artifactId>MultiThreading</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>

<name>MultiThreading</name>
<url>http://maven.apache.org</url>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
46 changes: 46 additions & 0 deletions src/main/java/binaya/MultiThreading/App.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package binaya.MultiThreading;

/**
* Hello world!
*
*/
public class App
{
public static void main( String[] args )
{
B b=new B();
C c=new C();
b.printMessage();
c.printMessage();


}
}
class B{
public void printMessage() {
for (int i = 1; i <=5; i++) {
System.out.println("Hello from B");
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}
class C{
public void printMessage() {
for (int i = 1; i <=5; i++) {
System.out.println("Hello from C");
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}

}

38 changes: 38 additions & 0 deletions src/test/java/binaya/MultiThreading/AppTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package binaya.MultiThreading;

import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;

/**
* Unit test for simple App.
*/
public class AppTest
extends TestCase
{
/**
* Create the test case
*
* @param testName name of the test case
*/
public AppTest( String testName )
{
super( testName );
}

/**
* @return the suite of tests being tested
*/
public static Test suite()
{
return new TestSuite( AppTest.class );
}

/**
* Rigourous Test :-)
*/
public void testApp()
{
assertTrue( true );
}
}
Binary file added target/classes/binaya/MultiThreading/App.class
Binary file not shown.
Binary file added target/classes/binaya/MultiThreading/B.class
Binary file not shown.
Binary file added target/classes/binaya/MultiThreading/C.class
Binary file not shown.
Binary file not shown.

0 comments on commit 551bbc1

Please sign in to comment.