Commit f7cfaa5c authored by Mohamad Bashar Desoki's avatar Mohamad Bashar Desoki

Using Runnable

parent b73274ca
......@@ -4,7 +4,8 @@
<option name="autoReloadType" value="SELECTIVE" />
</component>
<component name="ChangeListManager">
<list default="true" id="58d4b7b2-63a8-4164-95ff-e494b5fc28c6" name="Changes" comment="Create Save Student Service using Thread">
<list default="true" id="58d4b7b2-63a8-4164-95ff-e494b5fc28c6" name="Changes" comment="Create Save Student Service using MultiThread">
<change afterPath="$PROJECT_DIR$/src/main/java/StudentServiceRunnable.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/test/java/StudentServiceTest.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/test/java/StudentServiceTest.java" afterDir="false" />
</list>
......@@ -39,32 +40,32 @@
&quot;last_opened_file_path&quot;: &quot;D:/HIAST Library/Teaching/PP/2024/lec1/Lec1-Threads&quot;
}
}</component>
<component name="RunManager" selected="JUnit.StudentServiceTest.testStudentServiceUsingThreads">
<configuration name="StudentServiceTest.testMultiStudentService" type="JUnit" factoryName="JUnit" temporary="true" nameIsGenerated="true">
<component name="RunManager" selected="JUnit.StudentServiceTest.testStudentServiceUsingLambdaRunnable">
<configuration name="StudentServiceTest.testStudentServiceUsingAnonymousRunnable" type="JUnit" factoryName="JUnit" temporary="true" nameIsGenerated="true">
<module name="Lec1-Threads" />
<option name="PACKAGE_NAME" value="" />
<option name="MAIN_CLASS_NAME" value="StudentServiceTest" />
<option name="METHOD_NAME" value="testMultiStudentService" />
<option name="METHOD_NAME" value="testStudentServiceUsingAnonymousRunnable" />
<option name="TEST_OBJECT" value="method" />
<method v="2">
<option name="Make" enabled="true" />
</method>
</configuration>
<configuration name="StudentServiceTest.testMultiStudentServiceUsingThreads" type="JUnit" factoryName="JUnit" temporary="true" nameIsGenerated="true">
<configuration name="StudentServiceTest.testStudentServiceUsingLambdaRunnable" type="JUnit" factoryName="JUnit" temporary="true" nameIsGenerated="true">
<module name="Lec1-Threads" />
<option name="PACKAGE_NAME" value="" />
<option name="MAIN_CLASS_NAME" value="StudentServiceTest" />
<option name="METHOD_NAME" value="testMultiStudentServiceUsingThreads" />
<option name="METHOD_NAME" value="testStudentServiceUsingLambdaRunnable" />
<option name="TEST_OBJECT" value="method" />
<method v="2">
<option name="Make" enabled="true" />
</method>
</configuration>
<configuration name="StudentServiceTest.testStudentService" type="JUnit" factoryName="JUnit" temporary="true" nameIsGenerated="true">
<configuration name="StudentServiceTest.testStudentServiceUsingRunnable" type="JUnit" factoryName="JUnit" temporary="true" nameIsGenerated="true">
<module name="Lec1-Threads" />
<option name="PACKAGE_NAME" value="" />
<option name="MAIN_CLASS_NAME" value="StudentServiceTest" />
<option name="METHOD_NAME" value="testStudentService" />
<option name="METHOD_NAME" value="testStudentServiceUsingRunnable" />
<option name="TEST_OBJECT" value="method" />
<method v="2">
<option name="Make" enabled="true" />
......@@ -92,11 +93,11 @@
</configuration>
<recent_temporary>
<list>
<item itemvalue="JUnit.StudentServiceTest.testStudentServiceUsingLambdaRunnable" />
<item itemvalue="JUnit.StudentServiceTest.testStudentServiceUsingAnonymousRunnable" />
<item itemvalue="JUnit.StudentServiceTest.testStudentServiceUsingRunnable" />
<item itemvalue="JUnit.StudentServiceTest.testStudentServiceUsingThreads" />
<item itemvalue="JUnit.StudentServiceTest.testStudentServiceUsingThread" />
<item itemvalue="JUnit.StudentServiceTest.testMultiStudentServiceUsingThreads" />
<item itemvalue="JUnit.StudentServiceTest.testMultiStudentService" />
<item itemvalue="JUnit.StudentServiceTest.testStudentService" />
</list>
</recent_temporary>
</component>
......@@ -123,7 +124,14 @@
<option name="project" value="LOCAL" />
<updated>1697615156687</updated>
</task>
<option name="localTasksCounter" value="3" />
<task id="LOCAL-00003" summary="Create Save Student Service using MultiThread">
<created>1697616295535</created>
<option name="number" value="00003" />
<option name="presentableId" value="LOCAL-00003" />
<option name="project" value="LOCAL" />
<updated>1697616295535</updated>
</task>
<option name="localTasksCounter" value="4" />
<servers />
</component>
<component name="Vcs.Log.Tabs.Properties">
......@@ -140,6 +148,7 @@
<component name="VcsManagerConfiguration">
<MESSAGE value="Create Save Student Service" />
<MESSAGE value="Create Save Student Service using Thread" />
<option name="LAST_COMMIT_MESSAGE" value="Create Save Student Service using Thread" />
<MESSAGE value="Create Save Student Service using MultiThread" />
<option name="LAST_COMMIT_MESSAGE" value="Create Save Student Service using MultiThread" />
</component>
</project>
\ No newline at end of file
public class StudentServiceRunnable implements Runnable{
private StudentService studentService;
private Student student;
public StudentServiceRunnable(StudentService studentService,Student student){
this.student=student;
this.studentService=studentService;
}
@Override
public void run(){
System.out.println("The name of the current name is: "+ Thread.currentThread().getName());
studentService.SaveStudent(student);
}
}
......@@ -100,4 +100,57 @@ public class StudentServiceTest extends TestCase {
System.out.println("Time Taken: "+ end);
}
public void testStudentServiceUsingRunnable()
{
StudentService studentService = new StudentService();
Student student = new Student("Mhd");
StudentServiceRunnable studentServiceRunnable = new StudentServiceRunnable(studentService,student);
Thread th = new Thread(studentServiceRunnable);
th.start();
try {
th.join();
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
}
public void testStudentServiceUsingAnonymousRunnable()
{
StudentService studentService = new StudentService();
Student student = new Student("Mhd");
// StudentServiceRunnable studentServiceRunnable = new StudentServiceRunnable(studentService,student);
Thread th = new Thread(new Runnable() {
@Override
public void run() {
studentService.SaveStudent(student);
}
});
th.start();
try {
th.join();
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
}
public void testStudentServiceUsingLambdaRunnable()
{
StudentService studentService = new StudentService();
Student student = new Student("Mhd");
// StudentServiceRunnable studentServiceRunnable = new StudentServiceRunnable(studentService,student);
Thread th = new Thread(() -> studentService.SaveStudent(student));
th.start();
try {
th.join();
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
}
}
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