Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
T
TestThreads
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Jean-Marie Place
TestThreads
Commits
ac2375d2
Commit
ac2375d2
authored
4 years ago
by
Jean-Marie Place
Browse files
Options
Downloads
Patches
Plain Diff
initial commit
parents
Branches
master
No related tags found
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/threads/FastFiller.java
+59
-0
59 additions, 0 deletions
src/threads/FastFiller.java
src/threads/Filler.java
+9
-0
9 additions, 0 deletions
src/threads/Filler.java
src/threads/Main.java
+18
-0
18 additions, 0 deletions
src/threads/Main.java
with
86 additions
and
0 deletions
src/threads/FastFiller.java
0 → 100644
+
59
−
0
View file @
ac2375d2
package
threads
;
public
class
FastFiller
{
class
PartialFiller
extends
Thread
{
double
[]
t
;
int
no
;
int
from
;
int
to
;
public
PartialFiller
(
int
no
,
double
[]
t
,
int
from
,
int
to
)
{
this
.
t
=
t
;
this
.
no
=
no
;
this
.
from
=
from
;
this
.
to
=
to
;
}
@Override
public
void
run
()
{
for
(
int
i
=
from
;
i
<
to
;
i
++)
{
t
[
i
]
=
Math
.
sin
(
i
+
0.0
);
}
System
.
out
.
print
(
no
+
" done."
);
}
}
private
final
int
nbThreads
;
public
FastFiller
(
int
nbThreads
)
{
this
.
nbThreads
=
nbThreads
;
}
public
void
fill
(
double
[]
t
)
{
Thread
[]
threads
;
int
[]
ranges
=
new
int
[
nbThreads
];
threads
=
new
Thread
[
nbThreads
];
int
rangeSize
=
t
.
length
/
nbThreads
;
ranges
[
ranges
.
length
-
1
]
=
t
.
length
;
int
bound
=
0
;
for
(
int
i
=
1
;
i
<
nbThreads
;
i
++)
{
int
nextBound
=
bound
+
rangeSize
;
threads
[
i
]
=
new
PartialFiller
(
i
,
t
,
bound
,
nextBound
);
bound
=
nextBound
;
}
threads
[
0
]
=
new
PartialFiller
(
nbThreads
,
t
,
bound
,
t
.
length
);
for
(
int
i
=
0
;
i
<
nbThreads
;
i
++)
{
threads
[
i
].
start
();
}
for
(
int
i
=
0
;
i
<
nbThreads
;
i
++)
{
try
{
threads
[
i
].
join
();
}
catch
(
InterruptedException
e
)
{
e
.
printStackTrace
();
}
}
System
.
out
.
println
();
}
}
This diff is collapsed.
Click to expand it.
src/threads/Filler.java
0 → 100644
+
9
−
0
View file @
ac2375d2
package
threads
;
public
class
Filler
{
public
void
fill
(
double
[]
t
)
{
for
(
int
i
=
0
;
i
<
t
.
length
;
i
++)
{
t
[
i
]
=
Math
.
sin
(
i
);
}
}
}
This diff is collapsed.
Click to expand it.
src/threads/Main.java
0 → 100644
+
18
−
0
View file @
ac2375d2
package
threads
;
public
class
Main
{
public
static
void
main
(
String
[]
args
)
{
double
[]
t
=
new
double
[
200000000
];
Filler
f
=
new
Filler
();
long
t0
;
t0
=
System
.
currentTimeMillis
();
f
.
fill
(
t
);
System
.
out
.
println
(
"no thread\t"
+
(
System
.
currentTimeMillis
()
-
t0
));
for
(
int
nbt
=
1
;
nbt
<
20
;
nbt
++)
{
FastFiller
ff
=
new
FastFiller
(
nbt
);
t0
=
System
.
currentTimeMillis
();
ff
.
fill
(
t
);
System
.
out
.
println
(
nbt
+
"\t"
+
(
System
.
currentTimeMillis
()
-
t0
));
}
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment