Skip to content

Commit

Permalink
11b - executor service
Browse files Browse the repository at this point in the history
  • Loading branch information
MarioBenov committed Apr 22, 2024
1 parent e9f2184 commit f10957b
Show file tree
Hide file tree
Showing 8 changed files with 119 additions and 0 deletions.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>org.example</groupId>
<artifactId>executor-service</artifactId>
<version>1.0-SNAPSHOT</version>

<properties>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package org.example;

import java.util.Collection;
import java.util.List;
import java.util.concurrent.*;

public class Main {
public static void main(String[] args) {
ExecutorService ex = Executors.newFixedThreadPool(5); // === .newSingleThreadExecutor();
((Executor)ex).execute(() -> System.out.println(Thread.currentThread().getName() + ": Inside thread"));
((Executor)ex).execute(() -> System.out.println(Thread.currentThread().getName() + ": Inside thread"));
((Executor)ex).execute(() -> System.out.println(Thread.currentThread().getName() + ": Inside thread"));
/*((Executor)ex).execute(() -> {
while(true) {
if(Thread.currentThread().isInterrupted()) return;
try {
Thread.sleep(100);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
}
});*/

Future res = ex.submit(() -> 1234);
try {
System.out.println(res.get());
} catch (InterruptedException | ExecutionException e) {
e.printStackTrace();
}

ex.shutdown();
//if(!ex.isShutdown()) {
// List<Runnable> tasks = ex.shutdownNow();
//tasks.get(0).
// }


}
}

0 comments on commit f10957b

Please sign in to comment.