Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in
Toggle navigation
F
ForkJoin
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
mohamadbashar.disoki
ForkJoin
Commits
0995dcb6
Commit
0995dcb6
authored
Mar 06, 2023
by
Mohamad Bashar Desoki
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
01. Save Records Sequentially
parent
8c591987
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
59 additions
and
0 deletions
+59
-0
README.md
README.md
+6
-0
Student.java
src/main/java/Resource/Student.java
+14
-0
StudentService.java
src/main/java/Service/StudentService.java
+17
-0
Threads.java
src/main/java/Threads.java
+2
-0
ThreadTest.java
src/test/java/ThreadTest.java
+20
-0
No files found.
README.md
View file @
0995dcb6
# ForkJoin Framework
# ForkJoin Framework
## Review Threads in Java
### Why we need threads?
Save 10 Records sequentially as Example.
src/main/java/Resource/Student.java
0 → 100644
View file @
0995dcb6
package
Resource
;
public
class
Student
{
private
String
name
;
public
String
getName
()
{
return
name
;
}
public
Student
(
String
name
)
{
this
.
name
=
name
;
}
}
src/main/java/Service/StudentService.java
0 → 100644
View file @
0995dcb6
package
Service
;
import
Resource.Student
;
import
java.util.UUID
;
public
class
StudentService
{
public
String
saveStudent
(
Student
std
){
System
.
out
.
println
(
"Saving Student: "
+
std
.
getName
());
try
{
Thread
.
sleep
(
1000
);
}
catch
(
InterruptedException
e
)
{
throw
new
RuntimeException
(
e
);
}
return
UUID
.
randomUUID
().
toString
();
}
}
src/main/java/Threads.java
0 → 100644
View file @
0995dcb6
public
class
Threads
{
}
src/test/java/ThreadTest.java
0 → 100644
View file @
0995dcb6
import
Resource.Student
;
import
Service.StudentService
;
import
junit.framework.TestCase
;
public
class
ThreadTest
extends
TestCase
{
public
void
testStudent
()
{
long
start
=
System
.
currentTimeMillis
();
StudentService
studentService
=
new
StudentService
();
for
(
int
i
=
1
;
i
<=
10
;
++
i
)
{
Student
std
=
new
Student
(
"student "
+
i
);
studentService
.
saveStudent
(
std
);
}
long
execTime
=
System
.
currentTimeMillis
()
-
start
;
System
.
out
.
println
(
"Execution Time: "
+
execTime
+
" ms"
);
}
}
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