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

Create Save Student Service using MultiThread

parent 33f955e5
...@@ -4,10 +4,8 @@ ...@@ -4,10 +4,8 @@
<option name="autoReloadType" value="SELECTIVE" /> <option name="autoReloadType" value="SELECTIVE" />
</component> </component>
<component name="ChangeListManager"> <component name="ChangeListManager">
<list default="true" id="58d4b7b2-63a8-4164-95ff-e494b5fc28c6" name="Changes" comment="Create Save Student Service"> <list default="true" id="58d4b7b2-63a8-4164-95ff-e494b5fc28c6" name="Changes" comment="Create Save Student Service using Thread">
<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$/.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" /> <change beforePath="$PROJECT_DIR$/src/test/java/StudentServiceTest.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/test/java/StudentServiceTest.java" afterDir="false" />
</list> </list>
<option name="SHOW_DIALOG" value="false" /> <option name="SHOW_DIALOG" value="false" />
...@@ -41,16 +39,7 @@ ...@@ -41,16 +39,7 @@
&quot;last_opened_file_path&quot;: &quot;D:/HIAST Library/Teaching/PP/2024/lec1/Lec1-Threads&quot; &quot;last_opened_file_path&quot;: &quot;D:/HIAST Library/Teaching/PP/2024/lec1/Lec1-Threads&quot;
} }
}</component> }</component>
<component name="RunManager" selected="JUnit.StudentServiceTest.testStudentServiceUsingThread"> <component name="RunManager" selected="JUnit.StudentServiceTest.testStudentServiceUsingThreads">
<configuration name="StudentServiceTest" 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="TEST_OBJECT" value="class" />
<method v="2">
<option name="Make" enabled="true" />
</method>
</configuration>
<configuration name="StudentServiceTest.testMultiStudentService" type="JUnit" factoryName="JUnit" temporary="true" nameIsGenerated="true"> <configuration name="StudentServiceTest.testMultiStudentService" type="JUnit" factoryName="JUnit" temporary="true" nameIsGenerated="true">
<module name="Lec1-Threads" /> <module name="Lec1-Threads" />
<option name="PACKAGE_NAME" value="" /> <option name="PACKAGE_NAME" value="" />
...@@ -91,13 +80,23 @@ ...@@ -91,13 +80,23 @@
<option name="Make" enabled="true" /> <option name="Make" enabled="true" />
</method> </method>
</configuration> </configuration>
<configuration name="StudentServiceTest.testStudentServiceUsingThreads" 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="testStudentServiceUsingThreads" />
<option name="TEST_OBJECT" value="method" />
<method v="2">
<option name="Make" enabled="true" />
</method>
</configuration>
<recent_temporary> <recent_temporary>
<list> <list>
<item itemvalue="JUnit.StudentServiceTest.testStudentServiceUsingThreads" />
<item itemvalue="JUnit.StudentServiceTest.testStudentServiceUsingThread" /> <item itemvalue="JUnit.StudentServiceTest.testStudentServiceUsingThread" />
<item itemvalue="JUnit.StudentServiceTest.testMultiStudentServiceUsingThreads" /> <item itemvalue="JUnit.StudentServiceTest.testMultiStudentServiceUsingThreads" />
<item itemvalue="JUnit.StudentServiceTest.testMultiStudentService" /> <item itemvalue="JUnit.StudentServiceTest.testMultiStudentService" />
<item itemvalue="JUnit.StudentServiceTest.testStudentService" /> <item itemvalue="JUnit.StudentServiceTest.testStudentService" />
<item itemvalue="JUnit.StudentServiceTest" />
</list> </list>
</recent_temporary> </recent_temporary>
</component> </component>
...@@ -117,7 +116,14 @@ ...@@ -117,7 +116,14 @@
<option name="project" value="LOCAL" /> <option name="project" value="LOCAL" />
<updated>1697611342313</updated> <updated>1697611342313</updated>
</task> </task>
<option name="localTasksCounter" value="2" /> <task id="LOCAL-00002" summary="Create Save Student Service using Thread">
<created>1697615156687</created>
<option name="number" value="00002" />
<option name="presentableId" value="LOCAL-00002" />
<option name="project" value="LOCAL" />
<updated>1697615156687</updated>
</task>
<option name="localTasksCounter" value="3" />
<servers /> <servers />
</component> </component>
<component name="Vcs.Log.Tabs.Properties"> <component name="Vcs.Log.Tabs.Properties">
...@@ -133,6 +139,7 @@ ...@@ -133,6 +139,7 @@
</component> </component>
<component name="VcsManagerConfiguration"> <component name="VcsManagerConfiguration">
<MESSAGE value="Create Save Student Service" /> <MESSAGE value="Create Save Student Service" />
<option name="LAST_COMMIT_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" />
</component> </component>
</project> </project>
\ No newline at end of file
import junit.framework.TestCase; import junit.framework.TestCase;
import java.util.ArrayList;
import java.util.List;
public class StudentServiceTest extends TestCase { public class StudentServiceTest extends TestCase {
public void testStudentService() public void testStudentService()
...@@ -47,4 +50,54 @@ public class StudentServiceTest extends TestCase { ...@@ -47,4 +50,54 @@ public class StudentServiceTest extends TestCase {
System.out.println("Time Taken: "+ end); System.out.println("Time Taken: "+ end);
} }
public void testStudentServiceUsingThreadsNotReally()
{
long StartTime= System.currentTimeMillis();
StudentService svc = new StudentService();
for (int i= 0; i<10;i++) {
Student student = new Student("Mhd "+i);
StudentServiceThread studentServiceThread = new StudentServiceThread(svc, student);
studentServiceThread.setName("MyTestThread"+i);
studentServiceThread.start();
try {
studentServiceThread.join();
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
}
// studentServiceThread.run();
long end = System.currentTimeMillis()- StartTime;
System.out.println("Time Taken: "+ end);
}
public void testStudentServiceUsingThreads()
{
long StartTime= System.currentTimeMillis();
StudentService svc = new StudentService();
List<StudentServiceThread> studentServiceThreadList = new ArrayList<>();
for (int i= 0; i<10;i++) {
Student student = new Student("Mhd "+i);
StudentServiceThread studentServiceThread = new StudentServiceThread(svc, student);
studentServiceThread.setName("MyTestThread"+i);
studentServiceThread.start();
studentServiceThreadList.add(studentServiceThread);
}
// studentServiceThread.run();
for(StudentServiceThread studentServiceThread: studentServiceThreadList){
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