Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in
Toggle navigation
P
PP-01-Threads-Review
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
ahmad.abdulla
PP-01-Threads-Review
Commits
33f955e5
Commit
33f955e5
authored
Oct 18, 2023
by
Mohamad Bashar Desoki
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Create Save Student Service using Thread
parent
721929cf
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
102 additions
and
6 deletions
+102
-6
workspace.xml
.idea/workspace.xml
+50
-6
StudentService.java
src/main/java/StudentService.java
+1
-0
StudentServiceThread.java
src/main/java/StudentServiceThread.java
+16
-0
StudentServiceTest.java
src/test/java/StudentServiceTest.java
+35
-0
No files found.
.idea/workspace.xml
View file @
33f955e5
...
@@ -4,12 +4,11 @@
...
@@ -4,12 +4,11 @@
<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=
""
>
<list
default=
"true"
id=
"58d4b7b2-63a8-4164-95ff-e494b5fc28c6"
name=
"Changes"
comment=
"Create Save Student Service"
>
<change
afterPath=
"$PROJECT_DIR$/src/main/java/Student.java"
afterDir=
"false"
/>
<change
afterPath=
"$PROJECT_DIR$/src/main/java/StudentServiceThread.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"
/>
<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"
/>
</list>
</list>
<option
name=
"SHOW_DIALOG"
value=
"false"
/>
<option
name=
"SHOW_DIALOG"
value=
"false"
/>
<option
name=
"HIGHLIGHT_CONFLICTS"
value=
"true"
/>
<option
name=
"HIGHLIGHT_CONFLICTS"
value=
"true"
/>
...
@@ -42,7 +41,7 @@
...
@@ -42,7 +41,7 @@
"
last_opened_file_path
"
:
"
D:/HIAST Library/Teaching/PP/2024/lec1/Lec1-Threads
"
"
last_opened_file_path
"
:
"
D:/HIAST Library/Teaching/PP/2024/lec1/Lec1-Threads
"
}
}
}
</component>
}
</component>
<component
name=
"RunManager"
selected=
"JUnit.StudentServiceTest.testStudentService"
>
<component
name=
"RunManager"
selected=
"JUnit.StudentServiceTest.testStudentService
UsingThread
"
>
<configuration
name=
"StudentServiceTest"
type=
"JUnit"
factoryName=
"JUnit"
temporary=
"true"
nameIsGenerated=
"true"
>
<configuration
name=
"StudentServiceTest"
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=
""
/>
...
@@ -52,6 +51,26 @@
...
@@ -52,6 +51,26 @@
<option
name=
"Make"
enabled=
"true"
/>
<option
name=
"Make"
enabled=
"true"
/>
</method>
</method>
</configuration>
</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"
>
<configuration
name=
"StudentServiceTest.testStudentService"
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=
""
/>
...
@@ -62,8 +81,21 @@
...
@@ -62,8 +81,21 @@
<option
name=
"Make"
enabled=
"true"
/>
<option
name=
"Make"
enabled=
"true"
/>
</method>
</method>
</configuration>
</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>
<recent_temporary>
<list>
<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.testStudentService"
/>
<item
itemvalue=
"JUnit.StudentServiceTest"
/>
<item
itemvalue=
"JUnit.StudentServiceTest"
/>
</list>
</list>
...
@@ -78,6 +110,14 @@
...
@@ -78,6 +110,14 @@
<option
name=
"presentableId"
value=
"Default"
/>
<option
name=
"presentableId"
value=
"Default"
/>
<updated>
1697610341846
</updated>
<updated>
1697610341846
</updated>
</task>
</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
/>
<servers
/>
</component>
</component>
<component
name=
"Vcs.Log.Tabs.Properties"
>
<component
name=
"Vcs.Log.Tabs.Properties"
>
...
@@ -91,4 +131,8 @@
...
@@ -91,4 +131,8 @@
</map>
</map>
</option>
</option>
</component>
</component>
<component
name=
"VcsManagerConfiguration"
>
<MESSAGE
value=
"Create Save Student Service"
/>
<option
name=
"LAST_COMMIT_MESSAGE"
value=
"Create Save Student Service"
/>
</component>
</project>
</project>
\ No newline at end of file
src/main/java/StudentService.java
View file @
33f955e5
...
@@ -8,6 +8,7 @@ public class StudentService {
...
@@ -8,6 +8,7 @@ public class StudentService {
}
catch
(
InterruptedException
e
)
{
}
catch
(
InterruptedException
e
)
{
throw
new
RuntimeException
(
e
);
throw
new
RuntimeException
(
e
);
}
}
System
.
out
.
println
(
"Saving Student is Completed: "
+
student
.
getName
());
return
UUID
.
randomUUID
().
toString
();
return
UUID
.
randomUUID
().
toString
();
}
}
}
}
src/main/java/StudentServiceThread.java
0 → 100644
View file @
33f955e5
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
);
}
}
src/test/java/StudentServiceTest.java
View file @
33f955e5
...
@@ -12,4 +12,39 @@ public class StudentServiceTest extends TestCase {
...
@@ -12,4 +12,39 @@ public class StudentServiceTest extends TestCase {
System
.
out
.
println
(
"Time Taken: "
+
end
);
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
);
}
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment