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
f7cfaa5c
Commit
f7cfaa5c
authored
Oct 18, 2023
by
Mohamad Bashar Desoki
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Using Runnable
parent
b73274ca
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
90 additions
and
13 deletions
+90
-13
workspace.xml
.idea/workspace.xml
+22
-13
StudentServiceRunnable.java
src/main/java/StudentServiceRunnable.java
+15
-0
StudentServiceTest.java
src/test/java/StudentServiceTest.java
+53
-0
No files found.
.idea/workspace.xml
View file @
f7cfaa5c
...
...
@@ -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 @@
"
last_opened_file_path
"
:
"
D:/HIAST Library/Teaching/PP/2024/lec1/Lec1-Threads
"
}
}
</component>
<component
name=
"RunManager"
selected=
"JUnit.StudentServiceTest.testStudentServiceUsing
Threads
"
>
<configuration
name=
"StudentServiceTest.test
MultiStudentServic
e"
type=
"JUnit"
factoryName=
"JUnit"
temporary=
"true"
nameIsGenerated=
"true"
>
<component
name=
"RunManager"
selected=
"JUnit.StudentServiceTest.testStudentServiceUsing
LambdaRunnable
"
>
<configuration
name=
"StudentServiceTest.test
StudentServiceUsingAnonymousRunnabl
e"
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=
"test
MultiStudentServic
e"
/>
<option
name=
"METHOD_NAME"
value=
"test
StudentServiceUsingAnonymousRunnabl
e"
/>
<option
name=
"TEST_OBJECT"
value=
"method"
/>
<method
v=
"2"
>
<option
name=
"Make"
enabled=
"true"
/>
</method>
</configuration>
<configuration
name=
"StudentServiceTest.test
MultiStudentServiceUsingThreads
"
type=
"JUnit"
factoryName=
"JUnit"
temporary=
"true"
nameIsGenerated=
"true"
>
<configuration
name=
"StudentServiceTest.test
StudentServiceUsingLambdaRunnable
"
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=
"test
MultiStudentServiceUsingThreads
"
/>
<option
name=
"METHOD_NAME"
value=
"test
StudentServiceUsingLambdaRunnable
"
/>
<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
UsingRunnable
"
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=
"testStudentService
UsingRunnable
"
/>
<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
src/main/java/StudentServiceRunnable.java
0 → 100644
View file @
f7cfaa5c
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
);
}
}
src/test/java/StudentServiceTest.java
View file @
f7cfaa5c
...
...
@@ -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
);
}
}
}
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