diff --git a/code/java/ThreadPoolExecutorDemo/.idea/.gitignore b/code/java/ThreadPoolExecutorDemo/.idea/.gitignore deleted file mode 100644 index 5c98b428..00000000 --- a/code/java/ThreadPoolExecutorDemo/.idea/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -# Default ignored files -/workspace.xml \ No newline at end of file diff --git a/code/java/ThreadPoolExecutorDemo/.idea/checkstyle-idea.xml b/code/java/ThreadPoolExecutorDemo/.idea/checkstyle-idea.xml deleted file mode 100644 index e61c523d..00000000 --- a/code/java/ThreadPoolExecutorDemo/.idea/checkstyle-idea.xml +++ /dev/null @@ -1,16 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/code/java/ThreadPoolExecutorDemo/.idea/inspectionProfiles/Project_Default.xml b/code/java/ThreadPoolExecutorDemo/.idea/inspectionProfiles/Project_Default.xml deleted file mode 100644 index 6560a989..00000000 --- a/code/java/ThreadPoolExecutorDemo/.idea/inspectionProfiles/Project_Default.xml +++ /dev/null @@ -1,36 +0,0 @@ - - - - \ No newline at end of file diff --git a/code/java/ThreadPoolExecutorDemo/.idea/misc.xml b/code/java/ThreadPoolExecutorDemo/.idea/misc.xml deleted file mode 100644 index 05483570..00000000 --- a/code/java/ThreadPoolExecutorDemo/.idea/misc.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/code/java/ThreadPoolExecutorDemo/.idea/modules.xml b/code/java/ThreadPoolExecutorDemo/.idea/modules.xml deleted file mode 100644 index 864cd10e..00000000 --- a/code/java/ThreadPoolExecutorDemo/.idea/modules.xml +++ /dev/null @@ -1,8 +0,0 @@ - - - - - - - - \ No newline at end of file diff --git a/code/java/ThreadPoolExecutorDemo/.idea/uiDesigner.xml b/code/java/ThreadPoolExecutorDemo/.idea/uiDesigner.xml deleted file mode 100644 index e96534fb..00000000 --- a/code/java/ThreadPoolExecutorDemo/.idea/uiDesigner.xml +++ /dev/null @@ -1,124 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/code/java/ThreadPoolExecutorDemo/.idea/vcs.xml b/code/java/ThreadPoolExecutorDemo/.idea/vcs.xml deleted file mode 100644 index c2365ab1..00000000 --- a/code/java/ThreadPoolExecutorDemo/.idea/vcs.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/code/java/ThreadPoolExecutorDemo/ThreadPoolExecutorDemo.iml b/code/java/ThreadPoolExecutorDemo/ThreadPoolExecutorDemo.iml deleted file mode 100644 index c90834f2..00000000 --- a/code/java/ThreadPoolExecutorDemo/ThreadPoolExecutorDemo.iml +++ /dev/null @@ -1,11 +0,0 @@ - - - - - - - - - - - \ No newline at end of file diff --git a/code/java/ThreadPoolExecutorDemo/out/production/ThreadPoolExecutorDemo/META-INF/ThreadPoolExecutorDemo.kotlin_module b/code/java/ThreadPoolExecutorDemo/out/production/ThreadPoolExecutorDemo/META-INF/ThreadPoolExecutorDemo.kotlin_module deleted file mode 100644 index 2983af70..00000000 Binary files a/code/java/ThreadPoolExecutorDemo/out/production/ThreadPoolExecutorDemo/META-INF/ThreadPoolExecutorDemo.kotlin_module and /dev/null differ diff --git a/code/java/ThreadPoolExecutorDemo/out/production/ThreadPoolExecutorDemo/callable/CallableDemo.class b/code/java/ThreadPoolExecutorDemo/out/production/ThreadPoolExecutorDemo/callable/CallableDemo.class deleted file mode 100644 index 70861e73..00000000 Binary files a/code/java/ThreadPoolExecutorDemo/out/production/ThreadPoolExecutorDemo/callable/CallableDemo.class and /dev/null differ diff --git a/code/java/ThreadPoolExecutorDemo/out/production/ThreadPoolExecutorDemo/callable/MyCallable.class b/code/java/ThreadPoolExecutorDemo/out/production/ThreadPoolExecutorDemo/callable/MyCallable.class deleted file mode 100644 index 283e340b..00000000 Binary files a/code/java/ThreadPoolExecutorDemo/out/production/ThreadPoolExecutorDemo/callable/MyCallable.class and /dev/null differ diff --git a/code/java/ThreadPoolExecutorDemo/out/production/ThreadPoolExecutorDemo/common/ThreadPoolConstants.class b/code/java/ThreadPoolExecutorDemo/out/production/ThreadPoolExecutorDemo/common/ThreadPoolConstants.class deleted file mode 100644 index 07214fc7..00000000 Binary files a/code/java/ThreadPoolExecutorDemo/out/production/ThreadPoolExecutorDemo/common/ThreadPoolConstants.class and /dev/null differ diff --git a/code/java/ThreadPoolExecutorDemo/out/production/ThreadPoolExecutorDemo/scheduledThreadPoolExecutor/ScheduledThreadPoolExecutorDemo.class b/code/java/ThreadPoolExecutorDemo/out/production/ThreadPoolExecutorDemo/scheduledThreadPoolExecutor/ScheduledThreadPoolExecutorDemo.class deleted file mode 100644 index dc98bc8f..00000000 Binary files a/code/java/ThreadPoolExecutorDemo/out/production/ThreadPoolExecutorDemo/scheduledThreadPoolExecutor/ScheduledThreadPoolExecutorDemo.class and /dev/null differ diff --git a/code/java/ThreadPoolExecutorDemo/out/production/ThreadPoolExecutorDemo/scheduledThreadPoolExecutor/Task.class b/code/java/ThreadPoolExecutorDemo/out/production/ThreadPoolExecutorDemo/scheduledThreadPoolExecutor/Task.class deleted file mode 100644 index 9920a634..00000000 Binary files a/code/java/ThreadPoolExecutorDemo/out/production/ThreadPoolExecutorDemo/scheduledThreadPoolExecutor/Task.class and /dev/null differ diff --git a/code/java/ThreadPoolExecutorDemo/out/production/ThreadPoolExecutorDemo/threadPoolExecutor/MyRunnable.class b/code/java/ThreadPoolExecutorDemo/out/production/ThreadPoolExecutorDemo/threadPoolExecutor/MyRunnable.class deleted file mode 100644 index c1cf37ca..00000000 Binary files a/code/java/ThreadPoolExecutorDemo/out/production/ThreadPoolExecutorDemo/threadPoolExecutor/MyRunnable.class and /dev/null differ diff --git a/code/java/ThreadPoolExecutorDemo/out/production/ThreadPoolExecutorDemo/threadPoolExecutor/ThreadPoolExecutorDemo.class b/code/java/ThreadPoolExecutorDemo/out/production/ThreadPoolExecutorDemo/threadPoolExecutor/ThreadPoolExecutorDemo.class deleted file mode 100644 index 80c34f4d..00000000 Binary files a/code/java/ThreadPoolExecutorDemo/out/production/ThreadPoolExecutorDemo/threadPoolExecutor/ThreadPoolExecutorDemo.class and /dev/null differ diff --git a/code/java/ThreadPoolExecutorDemo/src/callable/CallableDemo.java b/code/java/ThreadPoolExecutorDemo/src/callable/CallableDemo.java deleted file mode 100644 index be762bda..00000000 --- a/code/java/ThreadPoolExecutorDemo/src/callable/CallableDemo.java +++ /dev/null @@ -1,49 +0,0 @@ -package callable; - -import java.util.ArrayList; -import java.util.Date; -import java.util.List; -import java.util.concurrent.ArrayBlockingQueue; -import java.util.concurrent.Callable; -import java.util.concurrent.ExecutionException; -import java.util.concurrent.Future; -import java.util.concurrent.ThreadPoolExecutor; -import java.util.concurrent.TimeUnit; - -import static common.ThreadPoolConstants.CORE_POOL_SIZE; -import static common.ThreadPoolConstants.KEEP_ALIVE_TIME; -import static common.ThreadPoolConstants.MAX_POOL_SIZE; -import static common.ThreadPoolConstants.QUEUE_CAPACITY; - -public class CallableDemo { - public static void main(String[] args) { - //使用阿里巴巴推荐的创建线程池的方式 - //通过ThreadPoolExecutor构造函数自定义参数创建 - ThreadPoolExecutor executor = new ThreadPoolExecutor( - CORE_POOL_SIZE, - MAX_POOL_SIZE, - KEEP_ALIVE_TIME, - TimeUnit.SECONDS, - new ArrayBlockingQueue<>(QUEUE_CAPACITY), - new ThreadPoolExecutor.CallerRunsPolicy()); - - List> futureList = new ArrayList<>(); - Callable callable = new MyCallable(); - for (int i = 0; i < 10; i++) { - //提交任务到线程池 - Future future = executor.submit(callable); - //将返回值 future 添加到 list,我们可以通过 future 获得 执行 Callable 得到的返回值 - futureList.add(future); - } - for (Future fut : futureList) { - try { - System.out.println(new Date() + "::" + fut.get()); - } catch (InterruptedException | ExecutionException e) { - e.printStackTrace(); - } - } - //关闭线程池 - executor.shutdown(); - } -} - diff --git a/code/java/ThreadPoolExecutorDemo/src/callable/MyCallable.java b/code/java/ThreadPoolExecutorDemo/src/callable/MyCallable.java deleted file mode 100644 index 53d540fb..00000000 --- a/code/java/ThreadPoolExecutorDemo/src/callable/MyCallable.java +++ /dev/null @@ -1,13 +0,0 @@ -package callable; - -import java.util.concurrent.Callable; - -public class MyCallable implements Callable { - - @Override - public String call() throws Exception { - Thread.sleep(1000); - //返回执行当前 Callable 的线程名字 - return Thread.currentThread().getName(); - } -} diff --git a/code/java/ThreadPoolExecutorDemo/src/common/ThreadPoolConstants.java b/code/java/ThreadPoolExecutorDemo/src/common/ThreadPoolConstants.java deleted file mode 100644 index 2018e86f..00000000 --- a/code/java/ThreadPoolExecutorDemo/src/common/ThreadPoolConstants.java +++ /dev/null @@ -1,11 +0,0 @@ -package common; - -public class ThreadPoolConstants { - public static final int CORE_POOL_SIZE = 5; - public static final int MAX_POOL_SIZE = 10; - public static final int QUEUE_CAPACITY = 100; - public static final Long KEEP_ALIVE_TIME = 1L; - private ThreadPoolConstants(){ - - } -} diff --git a/code/java/ThreadPoolExecutorDemo/src/threadPoolExecutor/MyRunnable.java b/code/java/ThreadPoolExecutorDemo/src/threadPoolExecutor/MyRunnable.java deleted file mode 100644 index 4ebf2dcb..00000000 --- a/code/java/ThreadPoolExecutorDemo/src/threadPoolExecutor/MyRunnable.java +++ /dev/null @@ -1,36 +0,0 @@ -package threadPoolExecutor; - -import java.util.Date; - -/** - * 这是一个简单的Runnable类,需要大约5秒钟来执行其任务。 - * @author shuang.kou - */ -public class MyRunnable implements Runnable { - - private String command; - - public MyRunnable(String s) { - this.command = s; - } - - @Override - public void run() { - System.out.println(Thread.currentThread().getName() + " Start. Time = " + new Date()); - processCommand(); - System.out.println(Thread.currentThread().getName() + " End. Time = " + new Date()); - } - - private void processCommand() { - try { - Thread.sleep(5000); - } catch (InterruptedException e) { - e.printStackTrace(); - } - } - - @Override - public String toString() { - return this.command; - } -} diff --git a/code/java/ThreadPoolExecutorDemo/src/threadPoolExecutor/ThreadPoolExecutorDemo.java b/code/java/ThreadPoolExecutorDemo/src/threadPoolExecutor/ThreadPoolExecutorDemo.java deleted file mode 100644 index 2e510cd6..00000000 --- a/code/java/ThreadPoolExecutorDemo/src/threadPoolExecutor/ThreadPoolExecutorDemo.java +++ /dev/null @@ -1,39 +0,0 @@ -package threadPoolExecutor; - -import java.util.concurrent.ArrayBlockingQueue; -import java.util.concurrent.ThreadPoolExecutor; -import java.util.concurrent.TimeUnit; - -import static common.ThreadPoolConstants.CORE_POOL_SIZE; -import static common.ThreadPoolConstants.KEEP_ALIVE_TIME; -import static common.ThreadPoolConstants.MAX_POOL_SIZE; -import static common.ThreadPoolConstants.QUEUE_CAPACITY; - - -public class ThreadPoolExecutorDemo { - - public static void main(String[] args) { - - //使用阿里巴巴推荐的创建线程池的方式 - //通过ThreadPoolExecutor构造函数自定义参数创建 - ThreadPoolExecutor executor = new ThreadPoolExecutor( - CORE_POOL_SIZE, - MAX_POOL_SIZE, - KEEP_ALIVE_TIME, - TimeUnit.SECONDS, - new ArrayBlockingQueue<>(QUEUE_CAPACITY), - new ThreadPoolExecutor.CallerRunsPolicy()); - - for (int i = 0; i < 10; i++) { - //创建WorkerThread对象(WorkerThread类实现了Runnable 接口) - Runnable worker = new MyRunnable("" + i); - //执行Runnable - executor.execute(worker); - } - //终止线程池 - executor.shutdown(); - while (!executor.isTerminated()) { - } - System.out.println("Finished all threads"); - } -}