-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
- Loading branch information
There are no files selected for viewing
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). | ||
// } | ||
|
||
|
||
} | ||
} |