Commit 33f955e5 authored by Mohamad Bashar Desoki's avatar Mohamad Bashar Desoki

Create Save Student Service using Thread

parent 721929cf
......@@ -4,12 +4,11 @@
<option name="autoReloadType" value="SELECTIVE" />
</component>
<component name="ChangeListManager">
<list default="true" id="58d4b7b2-63a8-4164-95ff-e494b5fc28c6" name="Changes" comment="">
<change afterPath="$PROJECT_DIR$/src/main/java/Student.java" afterDir="false" />
<change afterPath="$PROJECT_DIR$/src/main/java/StudentService.java" afterDir="false" />
<change afterPath="$PROJECT_DIR$/src/test/java/StudentServiceTest.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/.gitignore" beforeDir="false" afterPath="$PROJECT_DIR$/.gitignore" afterDir="false" />
<list default="true" id="58d4b7b2-63a8-4164-95ff-e494b5fc28c6" name="Changes" comment="Create Save Student Service">
<change afterPath="$PROJECT_DIR$/src/main/java/StudentServiceThread.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/main/java/StudentService.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/StudentService.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/test/java/StudentServiceTest.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/test/java/StudentServiceTest.java" afterDir="false" />
</list>
<option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" />
......@@ -42,7 +41,7 @@
&quot;last_opened_file_path&quot;: &quot;D:/HIAST Library/Teaching/PP/2024/lec1/Lec1-Threads&quot;
}
}</component>
<component name="RunManager" selected="JUnit.StudentServiceTest.testStudentService">
<component name="RunManager" selected="JUnit.StudentServiceTest.testStudentServiceUsingThread">
<configuration name="StudentServiceTest" type="JUnit" factoryName="JUnit" temporary="true" nameIsGenerated="true">
<module name="Lec1-Threads" />
<option name="PACKAGE_NAME" value="" />
......@@ -52,6 +51,26 @@
<option name="Make" enabled="true" />
</method>
</configuration>
<configuration name="StudentServiceTest.testMultiStudentService" 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="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">
<module name="Lec1-Threads" />
<option name="PACKAGE_NAME" value="" />
<option name="MAIN_CLASS_NAME" value="StudentServiceTest" />
<option name="METHOD_NAME" value="testMultiStudentServiceUsingThreads" />
<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">
<module name="Lec1-Threads" />
<option name="PACKAGE_NAME" value="" />
......@@ -62,8 +81,21 @@
<option name="Make" enabled="true" />
</method>
</configuration>
<configuration name="StudentServiceTest.testStudentServiceUsingThread" 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="testStudentServiceUsingThread" />
<option name="TEST_OBJECT" value="method" />
<method v="2">
<option name="Make" enabled="true" />
</method>
</configuration>
<recent_temporary>
<list>
<item itemvalue="JUnit.StudentServiceTest.testStudentServiceUsingThread" />
<item itemvalue="JUnit.StudentServiceTest.testMultiStudentServiceUsingThreads" />
<item itemvalue="JUnit.StudentServiceTest.testMultiStudentService" />
<item itemvalue="JUnit.StudentServiceTest.testStudentService" />
<item itemvalue="JUnit.StudentServiceTest" />
</list>
......@@ -78,6 +110,14 @@
<option name="presentableId" value="Default" />
<updated>1697610341846</updated>
</task>
<task id="LOCAL-00001" summary="Create Save Student Service">
<created>1697611342313</created>
<option name="number" value="00001" />
<option name="presentableId" value="LOCAL-00001" />
<option name="project" value="LOCAL" />
<updated>1697611342313</updated>
</task>
<option name="localTasksCounter" value="2" />
<servers />
</component>
<component name="Vcs.Log.Tabs.Properties">
......@@ -91,4 +131,8 @@
</map>
</option>
</component>
<component name="VcsManagerConfiguration">
<MESSAGE value="Create Save Student Service" />
<option name="LAST_COMMIT_MESSAGE" value="Create Save Student Service" />
</component>
</project>
\ No newline at end of file
......@@ -8,6 +8,7 @@ public class StudentService {
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
System.out.println("Saving Student is Completed: " + student.getName());
return UUID.randomUUID().toString();
}
}
public class StudentServiceThread extends Thread{
private StudentService studentService;
private Student student;
public StudentServiceThread(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);
}
}
......@@ -12,4 +12,39 @@ public class StudentServiceTest extends TestCase {
System.out.println("Time Taken: "+ end);
}
public void testMultiStudentService()
{
long StartTime= System.currentTimeMillis();
StudentService svc = new StudentService();
for (int i=0; i<10;i++) {
Student student = new Student("Mhd "+i);
svc.SaveStudent(student);
}
long end = System.currentTimeMillis()- StartTime;
System.out.println("Time Taken: "+ end);
}
public void testStudentServiceUsingThread()
{
long StartTime= System.currentTimeMillis();
System.out.println("The name of the current name is: "+ Thread.currentThread().getName());
StudentService svc = new StudentService();
Student student = new Student("Mhd");
StudentServiceThread studentServiceThread = new StudentServiceThread(svc,student);
studentServiceThread.setName("MyTestThread");
studentServiceThread.start();
// studentServiceThread.run();
try {
studentServiceThread.join();
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
long end = System.currentTimeMillis()- StartTime;
System.out.println("Time Taken: "+ end);
}
}
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