Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Coudy Hou
JavaGuide
提交
c0ac39b3
J
JavaGuide
项目概览
Coudy Hou
/
JavaGuide
与 Fork 源项目一致
从无法访问的项目Fork
通知
5
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
J
JavaGuide
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
c0ac39b3
编写于
2月 24, 2021
作者:
G
guide
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
移除代码
上级
90566402
变更
21
隐藏空白更改
内联
并排
Showing
21 changed file
with
0 addition
and
357 deletion
+0
-357
code/java/ThreadPoolExecutorDemo/.idea/.gitignore
code/java/ThreadPoolExecutorDemo/.idea/.gitignore
+0
-2
code/java/ThreadPoolExecutorDemo/.idea/checkstyle-idea.xml
code/java/ThreadPoolExecutorDemo/.idea/checkstyle-idea.xml
+0
-16
code/java/ThreadPoolExecutorDemo/.idea/inspectionProfiles/Project_Default.xml
...ExecutorDemo/.idea/inspectionProfiles/Project_Default.xml
+0
-36
code/java/ThreadPoolExecutorDemo/.idea/misc.xml
code/java/ThreadPoolExecutorDemo/.idea/misc.xml
+0
-6
code/java/ThreadPoolExecutorDemo/.idea/modules.xml
code/java/ThreadPoolExecutorDemo/.idea/modules.xml
+0
-8
code/java/ThreadPoolExecutorDemo/.idea/uiDesigner.xml
code/java/ThreadPoolExecutorDemo/.idea/uiDesigner.xml
+0
-124
code/java/ThreadPoolExecutorDemo/.idea/vcs.xml
code/java/ThreadPoolExecutorDemo/.idea/vcs.xml
+0
-6
code/java/ThreadPoolExecutorDemo/ThreadPoolExecutorDemo.iml
code/java/ThreadPoolExecutorDemo/ThreadPoolExecutorDemo.iml
+0
-11
code/java/ThreadPoolExecutorDemo/out/production/ThreadPoolExecutorDemo/META-INF/ThreadPoolExecutorDemo.kotlin_module
...xecutorDemo/META-INF/ThreadPoolExecutorDemo.kotlin_module
+0
-0
code/java/ThreadPoolExecutorDemo/out/production/ThreadPoolExecutorDemo/callable/CallableDemo.class
...uction/ThreadPoolExecutorDemo/callable/CallableDemo.class
+0
-0
code/java/ThreadPoolExecutorDemo/out/production/ThreadPoolExecutorDemo/callable/MyCallable.class
...oduction/ThreadPoolExecutorDemo/callable/MyCallable.class
+0
-0
code/java/ThreadPoolExecutorDemo/out/production/ThreadPoolExecutorDemo/common/ThreadPoolConstants.class
...n/ThreadPoolExecutorDemo/common/ThreadPoolConstants.class
+0
-0
code/java/ThreadPoolExecutorDemo/out/production/ThreadPoolExecutorDemo/scheduledThreadPoolExecutor/ScheduledThreadPoolExecutorDemo.class
...dThreadPoolExecutor/ScheduledThreadPoolExecutorDemo.class
+0
-0
code/java/ThreadPoolExecutorDemo/out/production/ThreadPoolExecutorDemo/scheduledThreadPoolExecutor/Task.class
...adPoolExecutorDemo/scheduledThreadPoolExecutor/Task.class
+0
-0
code/java/ThreadPoolExecutorDemo/out/production/ThreadPoolExecutorDemo/threadPoolExecutor/MyRunnable.class
...hreadPoolExecutorDemo/threadPoolExecutor/MyRunnable.class
+0
-0
code/java/ThreadPoolExecutorDemo/out/production/ThreadPoolExecutorDemo/threadPoolExecutor/ThreadPoolExecutorDemo.class
...cutorDemo/threadPoolExecutor/ThreadPoolExecutorDemo.class
+0
-0
code/java/ThreadPoolExecutorDemo/src/callable/CallableDemo.java
...ava/ThreadPoolExecutorDemo/src/callable/CallableDemo.java
+0
-49
code/java/ThreadPoolExecutorDemo/src/callable/MyCallable.java
.../java/ThreadPoolExecutorDemo/src/callable/MyCallable.java
+0
-13
code/java/ThreadPoolExecutorDemo/src/common/ThreadPoolConstants.java
...hreadPoolExecutorDemo/src/common/ThreadPoolConstants.java
+0
-11
code/java/ThreadPoolExecutorDemo/src/threadPoolExecutor/MyRunnable.java
...adPoolExecutorDemo/src/threadPoolExecutor/MyRunnable.java
+0
-36
code/java/ThreadPoolExecutorDemo/src/threadPoolExecutor/ThreadPoolExecutorDemo.java
...orDemo/src/threadPoolExecutor/ThreadPoolExecutorDemo.java
+0
-39
未找到文件。
code/java/ThreadPoolExecutorDemo/.idea/.gitignore
已删除
100644 → 0
浏览文件 @
90566402
# Default ignored files
/workspace.xml
\ No newline at end of file
code/java/ThreadPoolExecutorDemo/.idea/checkstyle-idea.xml
已删除
100644 → 0
浏览文件 @
90566402
<?xml version="1.0" encoding="UTF-8"?>
<project
version=
"4"
>
<component
name=
"CheckStyle-IDEA"
>
<option
name=
"configuration"
>
<map>
<entry
key=
"checkstyle-version"
value=
"8.25"
/>
<entry
key=
"copy-libs"
value=
"false"
/>
<entry
key=
"location-0"
value=
"BUNDLED:(bundled):Sun Checks"
/>
<entry
key=
"location-1"
value=
"BUNDLED:(bundled):Google Checks"
/>
<entry
key=
"scan-before-checkin"
value=
"false"
/>
<entry
key=
"scanscope"
value=
"JavaOnly"
/>
<entry
key=
"suppress-errors"
value=
"false"
/>
</map>
</option>
</component>
</project>
\ No newline at end of file
code/java/ThreadPoolExecutorDemo/.idea/inspectionProfiles/Project_Default.xml
已删除
100644 → 0
浏览文件 @
90566402
<component
name=
"InspectionProjectProfileManager"
>
<profile
version=
"1.0"
>
<option
name=
"myName"
value=
"Project Default"
/>
<inspection_tool
class=
"JavaDoc"
enabled=
"true"
level=
"WARNING"
enabled_by_default=
"true"
>
<option
name=
"TOP_LEVEL_CLASS_OPTIONS"
>
<value>
<option
name=
"ACCESS_JAVADOC_REQUIRED_FOR"
value=
"none"
/>
<option
name=
"REQUIRED_TAGS"
value=
""
/>
</value>
</option>
<option
name=
"INNER_CLASS_OPTIONS"
>
<value>
<option
name=
"ACCESS_JAVADOC_REQUIRED_FOR"
value=
"none"
/>
<option
name=
"REQUIRED_TAGS"
value=
""
/>
</value>
</option>
<option
name=
"METHOD_OPTIONS"
>
<value>
<option
name=
"ACCESS_JAVADOC_REQUIRED_FOR"
value=
"none"
/>
<option
name=
"REQUIRED_TAGS"
value=
"@return@param@throws or @exception"
/>
</value>
</option>
<option
name=
"FIELD_OPTIONS"
>
<value>
<option
name=
"ACCESS_JAVADOC_REQUIRED_FOR"
value=
"none"
/>
<option
name=
"REQUIRED_TAGS"
value=
""
/>
</value>
</option>
<option
name=
"IGNORE_DEPRECATED"
value=
"false"
/>
<option
name=
"IGNORE_JAVADOC_PERIOD"
value=
"true"
/>
<option
name=
"IGNORE_DUPLICATED_THROWS"
value=
"false"
/>
<option
name=
"IGNORE_POINT_TO_ITSELF"
value=
"false"
/>
<option
name=
"myAdditionalJavadocTags"
value=
"date"
/>
</inspection_tool>
</profile>
</component>
\ No newline at end of file
code/java/ThreadPoolExecutorDemo/.idea/misc.xml
已删除
100644 → 0
浏览文件 @
90566402
<?xml version="1.0" encoding="UTF-8"?>
<project
version=
"4"
>
<component
name=
"ProjectRootManager"
version=
"2"
languageLevel=
"JDK_1_8"
default=
"true"
project-jdk-name=
"1.8"
project-jdk-type=
"JavaSDK"
>
<output
url=
"file://$PROJECT_DIR$/out"
/>
</component>
</project>
\ No newline at end of file
code/java/ThreadPoolExecutorDemo/.idea/modules.xml
已删除
100644 → 0
浏览文件 @
90566402
<?xml version="1.0" encoding="UTF-8"?>
<project
version=
"4"
>
<component
name=
"ProjectModuleManager"
>
<modules>
<module
fileurl=
"file://$PROJECT_DIR$/ThreadPoolExecutorDemo.iml"
filepath=
"$PROJECT_DIR$/ThreadPoolExecutorDemo.iml"
/>
</modules>
</component>
</project>
\ No newline at end of file
code/java/ThreadPoolExecutorDemo/.idea/uiDesigner.xml
已删除
100644 → 0
浏览文件 @
90566402
<?xml version="1.0" encoding="UTF-8"?>
<project
version=
"4"
>
<component
name=
"Palette2"
>
<group
name=
"Swing"
>
<item
class=
"com.intellij.uiDesigner.HSpacer"
tooltip-text=
"Horizontal Spacer"
icon=
"/com/intellij/uiDesigner/icons/hspacer.png"
removable=
"false"
auto-create-binding=
"false"
can-attach-label=
"false"
>
<default-constraints
vsize-policy=
"1"
hsize-policy=
"6"
anchor=
"0"
fill=
"1"
/>
</item>
<item
class=
"com.intellij.uiDesigner.VSpacer"
tooltip-text=
"Vertical Spacer"
icon=
"/com/intellij/uiDesigner/icons/vspacer.png"
removable=
"false"
auto-create-binding=
"false"
can-attach-label=
"false"
>
<default-constraints
vsize-policy=
"6"
hsize-policy=
"1"
anchor=
"0"
fill=
"2"
/>
</item>
<item
class=
"javax.swing.JPanel"
icon=
"/com/intellij/uiDesigner/icons/panel.png"
removable=
"false"
auto-create-binding=
"false"
can-attach-label=
"false"
>
<default-constraints
vsize-policy=
"3"
hsize-policy=
"3"
anchor=
"0"
fill=
"3"
/>
</item>
<item
class=
"javax.swing.JScrollPane"
icon=
"/com/intellij/uiDesigner/icons/scrollPane.png"
removable=
"false"
auto-create-binding=
"false"
can-attach-label=
"true"
>
<default-constraints
vsize-policy=
"7"
hsize-policy=
"7"
anchor=
"0"
fill=
"3"
/>
</item>
<item
class=
"javax.swing.JButton"
icon=
"/com/intellij/uiDesigner/icons/button.png"
removable=
"false"
auto-create-binding=
"true"
can-attach-label=
"false"
>
<default-constraints
vsize-policy=
"0"
hsize-policy=
"3"
anchor=
"0"
fill=
"1"
/>
<initial-values>
<property
name=
"text"
value=
"Button"
/>
</initial-values>
</item>
<item
class=
"javax.swing.JRadioButton"
icon=
"/com/intellij/uiDesigner/icons/radioButton.png"
removable=
"false"
auto-create-binding=
"true"
can-attach-label=
"false"
>
<default-constraints
vsize-policy=
"0"
hsize-policy=
"3"
anchor=
"8"
fill=
"0"
/>
<initial-values>
<property
name=
"text"
value=
"RadioButton"
/>
</initial-values>
</item>
<item
class=
"javax.swing.JCheckBox"
icon=
"/com/intellij/uiDesigner/icons/checkBox.png"
removable=
"false"
auto-create-binding=
"true"
can-attach-label=
"false"
>
<default-constraints
vsize-policy=
"0"
hsize-policy=
"3"
anchor=
"8"
fill=
"0"
/>
<initial-values>
<property
name=
"text"
value=
"CheckBox"
/>
</initial-values>
</item>
<item
class=
"javax.swing.JLabel"
icon=
"/com/intellij/uiDesigner/icons/label.png"
removable=
"false"
auto-create-binding=
"false"
can-attach-label=
"false"
>
<default-constraints
vsize-policy=
"0"
hsize-policy=
"0"
anchor=
"8"
fill=
"0"
/>
<initial-values>
<property
name=
"text"
value=
"Label"
/>
</initial-values>
</item>
<item
class=
"javax.swing.JTextField"
icon=
"/com/intellij/uiDesigner/icons/textField.png"
removable=
"false"
auto-create-binding=
"true"
can-attach-label=
"true"
>
<default-constraints
vsize-policy=
"0"
hsize-policy=
"6"
anchor=
"8"
fill=
"1"
>
<preferred-size
width=
"150"
height=
"-1"
/>
</default-constraints>
</item>
<item
class=
"javax.swing.JPasswordField"
icon=
"/com/intellij/uiDesigner/icons/passwordField.png"
removable=
"false"
auto-create-binding=
"true"
can-attach-label=
"true"
>
<default-constraints
vsize-policy=
"0"
hsize-policy=
"6"
anchor=
"8"
fill=
"1"
>
<preferred-size
width=
"150"
height=
"-1"
/>
</default-constraints>
</item>
<item
class=
"javax.swing.JFormattedTextField"
icon=
"/com/intellij/uiDesigner/icons/formattedTextField.png"
removable=
"false"
auto-create-binding=
"true"
can-attach-label=
"true"
>
<default-constraints
vsize-policy=
"0"
hsize-policy=
"6"
anchor=
"8"
fill=
"1"
>
<preferred-size
width=
"150"
height=
"-1"
/>
</default-constraints>
</item>
<item
class=
"javax.swing.JTextArea"
icon=
"/com/intellij/uiDesigner/icons/textArea.png"
removable=
"false"
auto-create-binding=
"true"
can-attach-label=
"true"
>
<default-constraints
vsize-policy=
"6"
hsize-policy=
"6"
anchor=
"0"
fill=
"3"
>
<preferred-size
width=
"150"
height=
"50"
/>
</default-constraints>
</item>
<item
class=
"javax.swing.JTextPane"
icon=
"/com/intellij/uiDesigner/icons/textPane.png"
removable=
"false"
auto-create-binding=
"true"
can-attach-label=
"true"
>
<default-constraints
vsize-policy=
"6"
hsize-policy=
"6"
anchor=
"0"
fill=
"3"
>
<preferred-size
width=
"150"
height=
"50"
/>
</default-constraints>
</item>
<item
class=
"javax.swing.JEditorPane"
icon=
"/com/intellij/uiDesigner/icons/editorPane.png"
removable=
"false"
auto-create-binding=
"true"
can-attach-label=
"true"
>
<default-constraints
vsize-policy=
"6"
hsize-policy=
"6"
anchor=
"0"
fill=
"3"
>
<preferred-size
width=
"150"
height=
"50"
/>
</default-constraints>
</item>
<item
class=
"javax.swing.JComboBox"
icon=
"/com/intellij/uiDesigner/icons/comboBox.png"
removable=
"false"
auto-create-binding=
"true"
can-attach-label=
"true"
>
<default-constraints
vsize-policy=
"0"
hsize-policy=
"2"
anchor=
"8"
fill=
"1"
/>
</item>
<item
class=
"javax.swing.JTable"
icon=
"/com/intellij/uiDesigner/icons/table.png"
removable=
"false"
auto-create-binding=
"true"
can-attach-label=
"false"
>
<default-constraints
vsize-policy=
"6"
hsize-policy=
"6"
anchor=
"0"
fill=
"3"
>
<preferred-size
width=
"150"
height=
"50"
/>
</default-constraints>
</item>
<item
class=
"javax.swing.JList"
icon=
"/com/intellij/uiDesigner/icons/list.png"
removable=
"false"
auto-create-binding=
"true"
can-attach-label=
"false"
>
<default-constraints
vsize-policy=
"6"
hsize-policy=
"2"
anchor=
"0"
fill=
"3"
>
<preferred-size
width=
"150"
height=
"50"
/>
</default-constraints>
</item>
<item
class=
"javax.swing.JTree"
icon=
"/com/intellij/uiDesigner/icons/tree.png"
removable=
"false"
auto-create-binding=
"true"
can-attach-label=
"false"
>
<default-constraints
vsize-policy=
"6"
hsize-policy=
"6"
anchor=
"0"
fill=
"3"
>
<preferred-size
width=
"150"
height=
"50"
/>
</default-constraints>
</item>
<item
class=
"javax.swing.JTabbedPane"
icon=
"/com/intellij/uiDesigner/icons/tabbedPane.png"
removable=
"false"
auto-create-binding=
"true"
can-attach-label=
"false"
>
<default-constraints
vsize-policy=
"3"
hsize-policy=
"3"
anchor=
"0"
fill=
"3"
>
<preferred-size
width=
"200"
height=
"200"
/>
</default-constraints>
</item>
<item
class=
"javax.swing.JSplitPane"
icon=
"/com/intellij/uiDesigner/icons/splitPane.png"
removable=
"false"
auto-create-binding=
"false"
can-attach-label=
"false"
>
<default-constraints
vsize-policy=
"3"
hsize-policy=
"3"
anchor=
"0"
fill=
"3"
>
<preferred-size
width=
"200"
height=
"200"
/>
</default-constraints>
</item>
<item
class=
"javax.swing.JSpinner"
icon=
"/com/intellij/uiDesigner/icons/spinner.png"
removable=
"false"
auto-create-binding=
"true"
can-attach-label=
"true"
>
<default-constraints
vsize-policy=
"0"
hsize-policy=
"6"
anchor=
"8"
fill=
"1"
/>
</item>
<item
class=
"javax.swing.JSlider"
icon=
"/com/intellij/uiDesigner/icons/slider.png"
removable=
"false"
auto-create-binding=
"true"
can-attach-label=
"false"
>
<default-constraints
vsize-policy=
"0"
hsize-policy=
"6"
anchor=
"8"
fill=
"1"
/>
</item>
<item
class=
"javax.swing.JSeparator"
icon=
"/com/intellij/uiDesigner/icons/separator.png"
removable=
"false"
auto-create-binding=
"false"
can-attach-label=
"false"
>
<default-constraints
vsize-policy=
"6"
hsize-policy=
"6"
anchor=
"0"
fill=
"3"
/>
</item>
<item
class=
"javax.swing.JProgressBar"
icon=
"/com/intellij/uiDesigner/icons/progressbar.png"
removable=
"false"
auto-create-binding=
"true"
can-attach-label=
"false"
>
<default-constraints
vsize-policy=
"0"
hsize-policy=
"6"
anchor=
"0"
fill=
"1"
/>
</item>
<item
class=
"javax.swing.JToolBar"
icon=
"/com/intellij/uiDesigner/icons/toolbar.png"
removable=
"false"
auto-create-binding=
"false"
can-attach-label=
"false"
>
<default-constraints
vsize-policy=
"0"
hsize-policy=
"6"
anchor=
"0"
fill=
"1"
>
<preferred-size
width=
"-1"
height=
"20"
/>
</default-constraints>
</item>
<item
class=
"javax.swing.JToolBar$Separator"
icon=
"/com/intellij/uiDesigner/icons/toolbarSeparator.png"
removable=
"false"
auto-create-binding=
"false"
can-attach-label=
"false"
>
<default-constraints
vsize-policy=
"0"
hsize-policy=
"0"
anchor=
"0"
fill=
"1"
/>
</item>
<item
class=
"javax.swing.JScrollBar"
icon=
"/com/intellij/uiDesigner/icons/scrollbar.png"
removable=
"false"
auto-create-binding=
"true"
can-attach-label=
"false"
>
<default-constraints
vsize-policy=
"6"
hsize-policy=
"0"
anchor=
"0"
fill=
"2"
/>
</item>
</group>
</component>
</project>
\ No newline at end of file
code/java/ThreadPoolExecutorDemo/.idea/vcs.xml
已删除
100644 → 0
浏览文件 @
90566402
<?xml version="1.0" encoding="UTF-8"?>
<project
version=
"4"
>
<component
name=
"VcsDirectoryMappings"
>
<mapping
directory=
"$PROJECT_DIR$/../../.."
vcs=
"Git"
/>
</component>
</project>
\ No newline at end of file
code/java/ThreadPoolExecutorDemo/ThreadPoolExecutorDemo.iml
已删除
100644 → 0
浏览文件 @
90566402
<?xml version="1.0" encoding="UTF-8"?>
<module
type=
"JAVA_MODULE"
version=
"4"
>
<component
name=
"NewModuleRootManager"
inherit-compiler-output=
"true"
>
<exclude-output
/>
<content
url=
"file://$MODULE_DIR$"
>
<sourceFolder
url=
"file://$MODULE_DIR$/src"
isTestSource=
"false"
/>
</content>
<orderEntry
type=
"inheritedJdk"
/>
<orderEntry
type=
"sourceFolder"
forTests=
"false"
/>
</component>
</module>
\ No newline at end of file
code/java/ThreadPoolExecutorDemo/out/production/ThreadPoolExecutorDemo/META-INF/ThreadPoolExecutorDemo.kotlin_module
已删除
100644 → 0
浏览文件 @
90566402
文件已删除
code/java/ThreadPoolExecutorDemo/out/production/ThreadPoolExecutorDemo/callable/CallableDemo.class
已删除
100644 → 0
浏览文件 @
90566402
文件已删除
code/java/ThreadPoolExecutorDemo/out/production/ThreadPoolExecutorDemo/callable/MyCallable.class
已删除
100644 → 0
浏览文件 @
90566402
文件已删除
code/java/ThreadPoolExecutorDemo/out/production/ThreadPoolExecutorDemo/common/ThreadPoolConstants.class
已删除
100644 → 0
浏览文件 @
90566402
文件已删除
code/java/ThreadPoolExecutorDemo/out/production/ThreadPoolExecutorDemo/scheduledThreadPoolExecutor/ScheduledThreadPoolExecutorDemo.class
已删除
100644 → 0
浏览文件 @
90566402
文件已删除
code/java/ThreadPoolExecutorDemo/out/production/ThreadPoolExecutorDemo/scheduledThreadPoolExecutor/Task.class
已删除
100644 → 0
浏览文件 @
90566402
文件已删除
code/java/ThreadPoolExecutorDemo/out/production/ThreadPoolExecutorDemo/threadPoolExecutor/MyRunnable.class
已删除
100644 → 0
浏览文件 @
90566402
文件已删除
code/java/ThreadPoolExecutorDemo/out/production/ThreadPoolExecutorDemo/threadPoolExecutor/ThreadPoolExecutorDemo.class
已删除
100644 → 0
浏览文件 @
90566402
文件已删除
code/java/ThreadPoolExecutorDemo/src/callable/CallableDemo.java
已删除
100644 → 0
浏览文件 @
90566402
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
<
Future
<
String
>>
futureList
=
new
ArrayList
<>();
Callable
<
String
>
callable
=
new
MyCallable
();
for
(
int
i
=
0
;
i
<
10
;
i
++)
{
//提交任务到线程池
Future
<
String
>
future
=
executor
.
submit
(
callable
);
//将返回值 future 添加到 list,我们可以通过 future 获得 执行 Callable 得到的返回值
futureList
.
add
(
future
);
}
for
(
Future
<
String
>
fut
:
futureList
)
{
try
{
System
.
out
.
println
(
new
Date
()
+
"::"
+
fut
.
get
());
}
catch
(
InterruptedException
|
ExecutionException
e
)
{
e
.
printStackTrace
();
}
}
//关闭线程池
executor
.
shutdown
();
}
}
code/java/ThreadPoolExecutorDemo/src/callable/MyCallable.java
已删除
100644 → 0
浏览文件 @
90566402
package
callable
;
import
java.util.concurrent.Callable
;
public
class
MyCallable
implements
Callable
<
String
>
{
@Override
public
String
call
()
throws
Exception
{
Thread
.
sleep
(
1000
);
//返回执行当前 Callable 的线程名字
return
Thread
.
currentThread
().
getName
();
}
}
code/java/ThreadPoolExecutorDemo/src/common/ThreadPoolConstants.java
已删除
100644 → 0
浏览文件 @
90566402
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
(){
}
}
code/java/ThreadPoolExecutorDemo/src/threadPoolExecutor/MyRunnable.java
已删除
100644 → 0
浏览文件 @
90566402
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
;
}
}
code/java/ThreadPoolExecutorDemo/src/threadPoolExecutor/ThreadPoolExecutorDemo.java
已删除
100644 → 0
浏览文件 @
90566402
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"
);
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录