Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
multithreading
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
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
DAI 26-27
multithreading
Commits
b8c3bf37
Commit
b8c3bf37
authored
Sep 26, 2026
by
Miguel Reboiro-Jato
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Adds virtual threads example
parent
29d4a024
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
123 additions
and
3 deletions
+123
-3
pom.xml
pom.xml
+2
-2
EchoBenchmark.java
src/main/java/es/uvigo/esei/dai/threads/EchoBenchmark.java
+74
-0
VirtualThreadEchoServer.java
...go/esei/dai/threads/example4/VirtualThreadEchoServer.java
+46
-0
AsynchronousMultiThreadedEchoServer.java
...threads/example5/AsynchronousMultiThreadedEchoServer.java
+1
-1
No files found.
pom.xml
View file @
b8c3bf37
...
...
@@ -32,8 +32,8 @@
</licenses>
<properties>
<maven.compiler.source>
1
1
</maven.compiler.source>
<maven.compiler.target>
1
1
</maven.compiler.target>
<maven.compiler.source>
2
1
</maven.compiler.source>
<maven.compiler.target>
2
1
</maven.compiler.target>
<project.build.sourceEncoding>
UTF-8
</project.build.sourceEncoding>
<project.reporting.outputEncoding>
UTF-8
</project.reporting.outputEncoding>
...
...
src/main/java/es/uvigo/esei/dai/threads/EchoBenchmark.java
0 → 100644
View file @
b8c3bf37
/*-
* #%L
* Ejemplos de DAI - Multithilo
* %%
* Copyright (C) 2014 - 2026 Miguel Reboiro Jato
* %%
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public
* License along with this program. If not, see
* <http://www.gnu.org/licenses/gpl-3.0.html>.
* #L%
*/
package
es
.
uvigo
.
esei
.
dai
.
threads
;
import
java.io.BufferedReader
;
import
java.io.IOException
;
import
java.io.InputStreamReader
;
import
java.net.InetAddress
;
import
java.net.Socket
;
import
java.net.UnknownHostException
;
import
java.util.concurrent.ExecutorService
;
import
java.util.concurrent.Executors
;
import
java.util.concurrent.TimeUnit
;
public
class
EchoBenchmark
{
private
final
static
String
[]
MESSAGES
=
{
"Hello"
,
"How are you?"
,
"I'm fine"
};
public
static
class
EchoTask
implements
Runnable
{
@Override
public
void
run
()
{
try
(
Socket
socket
=
new
Socket
(
InetAddress
.
getLocalHost
(),
50000
))
{
// Conexión con el servidor
final
SocketIOManager
ioManager
=
new
SocketIOManager
(
socket
);
for
(
String
message
:
MESSAGES
)
{
ioManager
.
println
(
message
);
ioManager
.
readLine
();
}
ioManager
.
println
(
"quit"
);
}
catch
(
final
UnknownHostException
e
)
{
System
.
out
.
println
(
"Unknown host: localhost"
);
}
catch
(
final
IOException
e
)
{
System
.
out
.
println
(
"Connection error: "
+
e
.
getMessage
());
}
}
}
public
static
void
main
(
String
[]
args
)
throws
InterruptedException
{
long
millis
=
System
.
currentTimeMillis
();
ExecutorService
service
=
Executors
.
newVirtualThreadPerTaskExecutor
();
for
(
int
i
=
0
;
i
<
10_000
;
i
++)
{
service
.
submit
(
new
EchoTask
());
}
service
.
shutdown
();
service
.
awaitTermination
(
Long
.
MAX_VALUE
,
TimeUnit
.
DAYS
);
System
.
out
.
println
(
System
.
currentTimeMillis
()
-
millis
);
}
}
src/main/java/es/uvigo/esei/dai/threads/example4/VirtualThreadEchoServer.java
0 → 100644
View file @
b8c3bf37
/*-
* #%L
* Ejemplos de DAI - Multithilo
* %%
* Copyright (C) 2014 - 2023 Miguel Reboiro Jato
* %%
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public
* License along with this program. If not, see
* <http://www.gnu.org/licenses/gpl-3.0.html>.
* #L%
*/
package
es
.
uvigo
.
esei
.
dai
.
threads
.
example4
;
import
java.io.IOException
;
import
java.net.ServerSocket
;
import
java.net.Socket
;
import
java.util.concurrent.ExecutorService
;
import
java.util.concurrent.Executors
;
import
es.uvigo.esei.dai.threads.ServiceThread
;
public
class
VirtualThreadEchoServer
{
public
static
void
main
(
String
[]
args
)
{
try
(
ServerSocket
serverSocket
=
new
ServerSocket
(
50000
))
{
final
ExecutorService
threadPool
=
Executors
.
newVirtualThreadPerTaskExecutor
();
while
(
true
)
{
final
Socket
clientSocket
=
serverSocket
.
accept
();
threadPool
.
execute
(
new
ServiceThread
(
clientSocket
));
}
}
catch
(
final
IOException
e
)
{
System
.
err
.
println
(
"Server socket could not be created"
);
}
}
}
src/main/java/es/uvigo/esei/dai/threads/example
4
/AsynchronousMultiThreadedEchoServer.java
→
src/main/java/es/uvigo/esei/dai/threads/example
5
/AsynchronousMultiThreadedEchoServer.java
View file @
b8c3bf37
...
...
@@ -19,7 +19,7 @@
* <http://www.gnu.org/licenses/gpl-3.0.html>.
* #L%
*/
package
es
.
uvigo
.
esei
.
dai
.
threads
.
example
4
;
package
es
.
uvigo
.
esei
.
dai
.
threads
.
example
5
;
import
java.io.IOException
;
import
java.net.InetSocketAddress
;
...
...
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