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

Create Save Student Service using MultiThread

parent 33f955e5
......@@ -4,10 +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">
<change afterPath="$PROJECT_DIR$/src/main/java/StudentServiceThread.java" afterDir="false" />
<list default="true" id="58d4b7b2-63a8-4164-95ff-e494b5fc28c6" name="Changes" comment="Create Save Student Service using Thread">
<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" />
......@@ -41,16 +39,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.testStudentServiceUsingThread">
<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>
<component name="RunManager" selected="JUnit.StudentServiceTest.testStudentServiceUsingThreads">
<configuration name="StudentServiceTest.testMultiStudentService" type="JUnit" factoryName="JUnit" temporary="true" nameIsGenerated="true">
<module name="Lec1-Threads" />
<option name="PACKAGE_NAME" value="" />
......@@ -91,13 +80,23 @@
<option name="Make" enabled="true" />
</method>
</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>
<list>
<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" />
<item itemvalue="JUnit.StudentServiceTest" />
</list>
</recent_temporary>
</component>
......@@ -117,7 +116,14 @@
<option name="project" value="LOCAL" />
<updated>1697611342313</updated>
</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 />
</component>
<component name="Vcs.Log.Tabs.Properties">
......@@ -133,6 +139,7 @@
</component>
<component name="VcsManagerConfiguration">
<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>
</project>
\ No newline at end of file
import junit.framework.TestCase;
import java.util.ArrayList;
import java.util.List;
public class StudentServiceTest extends TestCase {
public void testStudentService()
......@@ -47,4 +50,54 @@ public class StudentServiceTest extends TestCase {
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