Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in / Register
Toggle navigation
Y
yzg-util
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
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
YZG
yzg-util
Commits
ecbad115
Commit
ecbad115
authored
May 15, 2020
by
yanzg
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
设置打包时可以通过GIT查看源码
parent
ca5fa79b
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
79 additions
and
21 deletions
+79
-21
MemoryCacheCenter.java
...in/java/com/yanzuoguang/util/cache/MemoryCacheCenter.java
+2
-1
AbstractThreadList.java
.../java/com/yanzuoguang/util/thread/AbstractThreadList.java
+19
-1
RunnableListAuto.java
...in/java/com/yanzuoguang/util/thread/RunnableListAuto.java
+35
-5
TestRunnableListAuto.java
yzg-util-base/src/test/java/thread/TestRunnableListAuto.java
+23
-14
No files found.
yzg-util-base/src/main/java/com/yanzuoguang/util/cache/MemoryCacheCenter.java
View file @
ecbad115
...
@@ -9,6 +9,7 @@ import java.util.Vector;
...
@@ -9,6 +9,7 @@ import java.util.Vector;
/**
/**
* 内存缓存中心,负责自动清除过期缓存
* 内存缓存中心,负责自动清除过期缓存
*
* @author 颜佐光
* @author 颜佐光
*/
*/
public
class
MemoryCacheCenter
{
public
class
MemoryCacheCenter
{
...
@@ -52,6 +53,6 @@ public class MemoryCacheCenter {
...
@@ -52,6 +53,6 @@ public class MemoryCacheCenter {
}
}
};
};
threadList
.
add
(
CLEAR_LIST
);
threadList
.
add
(
CLEAR_LIST
);
threadList
.
waitRun
();
threadList
.
waitRun
(
false
);
}
}
}
}
yzg-util-base/src/main/java/com/yanzuoguang/util/thread/AbstractThreadList.java
View file @
ecbad115
...
@@ -300,9 +300,18 @@ public abstract class AbstractThreadList<T extends Object> implements ThreadWait
...
@@ -300,9 +300,18 @@ public abstract class AbstractThreadList<T extends Object> implements ThreadWait
* 开启等待线程,一直等待到全部执行完毕
* 开启等待线程,一直等待到全部执行完毕
*/
*/
public
void
waitRun
()
{
public
void
waitRun
()
{
this
.
waitRun
(
true
);
}
/**
* 开启等待线程,一直等待到全部执行完毕
*/
public
void
waitRun
(
boolean
throwError
)
{
this
.
threadExecute
();
this
.
threadExecute
();
threadWait
.
waitFinally
();
threadWait
.
waitFinally
();
this
.
throwThreadError
();
if
(
throwError
)
{
this
.
throwThreadError
();
}
}
}
/**
/**
...
@@ -333,6 +342,15 @@ public abstract class AbstractThreadList<T extends Object> implements ThreadWait
...
@@ -333,6 +342,15 @@ public abstract class AbstractThreadList<T extends Object> implements ThreadWait
}
}
}
}
/**
* 获取所有错误信息
*
* @return 获取所有的错误信息
*/
public
List
<
RuntimeException
>
getExceptions
()
{
return
exceptions
;
}
/**
/**
* 抛出线程中的异常数据
* 抛出线程中的异常数据
*/
*/
...
...
yzg-util-base/src/main/java/com/yanzuoguang/util/thread/RunnableListAuto.java
View file @
ecbad115
...
@@ -30,7 +30,7 @@ public final class RunnableListAuto {
...
@@ -30,7 +30,7 @@ public final class RunnableListAuto {
* @param codes
* @param codes
*/
*/
public
static
AbstractThreadList
<
RunnableListAutoItem
>
run
(
Runnable
...
codes
)
{
public
static
AbstractThreadList
<
RunnableListAutoItem
>
run
(
Runnable
...
codes
)
{
return
run
(
Arrays
.
asList
(
codes
)
);
return
run
(
false
,
codes
);
}
}
/**
/**
...
@@ -39,11 +39,41 @@ public final class RunnableListAuto {
...
@@ -39,11 +39,41 @@ public final class RunnableListAuto {
* @param codes
* @param codes
*/
*/
public
static
AbstractThreadList
<
RunnableListAutoItem
>
run
(
List
<
Runnable
>
codes
)
{
public
static
AbstractThreadList
<
RunnableListAutoItem
>
run
(
List
<
Runnable
>
codes
)
{
return
run
(
false
,
codes
);
}
/**
* 将数据进行整理
*
* @param codes
* @return
*/
private
static
List
<
RunnableListAutoItem
>
convertRun
(
List
<
Runnable
>
codes
)
{
List
<
RunnableListAutoItem
>
autos
=
new
ArrayList
<
RunnableListAutoItem
>();
List
<
RunnableListAutoItem
>
autos
=
new
ArrayList
<
RunnableListAutoItem
>();
for
(
Runnable
code
:
codes
)
{
for
(
Runnable
code
:
codes
)
{
autos
.
add
(
new
RunnableListAutoItem
(
code
));
autos
.
add
(
new
RunnableListAutoItem
(
code
));
}
}
return
runAuto
(
autos
);
return
autos
;
}
/**
* 自动开启线程去执行代码,并根据执行时间调整先后顺序
*
* @param codes
*/
public
static
AbstractThreadList
<
RunnableListAutoItem
>
run
(
boolean
throwError
,
Runnable
...
codes
)
{
List
<
RunnableListAutoItem
>
autos
=
convertRun
(
Arrays
.
asList
(
codes
));
return
runAuto
(
throwError
,
autos
);
}
/**
* 自动开启线程去执行代码,并根据执行时间调整先后顺序
*
* @param codes
*/
public
static
AbstractThreadList
<
RunnableListAutoItem
>
run
(
boolean
throwError
,
List
<
Runnable
>
codes
)
{
List
<
RunnableListAutoItem
>
autos
=
convertRun
(
codes
);
return
runAuto
(
throwError
,
autos
);
}
}
/**
/**
...
@@ -52,7 +82,7 @@ public final class RunnableListAuto {
...
@@ -52,7 +82,7 @@ public final class RunnableListAuto {
* @param methods
* @param methods
*/
*/
public
static
AbstractThreadList
<
RunnableListAutoItem
>
runAuto
(
RunnableListAutoItem
...
methods
)
{
public
static
AbstractThreadList
<
RunnableListAutoItem
>
runAuto
(
RunnableListAutoItem
...
methods
)
{
return
runAuto
(
Arrays
.
asList
(
methods
));
return
runAuto
(
false
,
Arrays
.
asList
(
methods
));
}
}
/**
/**
...
@@ -60,7 +90,7 @@ public final class RunnableListAuto {
...
@@ -60,7 +90,7 @@ public final class RunnableListAuto {
*
*
* @param methods
* @param methods
*/
*/
public
static
AbstractThreadList
<
RunnableListAutoItem
>
runAuto
(
List
<
RunnableListAutoItem
>
methods
)
{
public
static
AbstractThreadList
<
RunnableListAutoItem
>
runAuto
(
boolean
throwError
,
List
<
RunnableListAutoItem
>
methods
)
{
// 没有执行过的列表
// 没有执行过的列表
List
<
RunnableListAutoItem
>
initList
=
new
ArrayList
<
RunnableListAutoItem
>();
List
<
RunnableListAutoItem
>
initList
=
new
ArrayList
<
RunnableListAutoItem
>();
...
@@ -100,7 +130,7 @@ public final class RunnableListAuto {
...
@@ -100,7 +130,7 @@ public final class RunnableListAuto {
// 添加到执行列表
// 添加到执行列表
threadList
.
add
(
initList
);
threadList
.
add
(
initList
);
// 等待线程执行完成
// 等待线程执行完成
threadList
.
waitRun
();
threadList
.
waitRun
(
throwError
);
return
threadList
;
return
threadList
;
}
}
...
...
yzg-util-base/src/test/java/thread/TestRunnableListAuto.java
View file @
ecbad115
...
@@ -8,25 +8,34 @@ import org.junit.Test;
...
@@ -8,25 +8,34 @@ import org.junit.Test;
public
class
TestRunnableListAuto
{
public
class
TestRunnableListAuto
{
private
void
runTest
(
boolean
throwError
)
{
RunnableListAuto
.
run
(
throwError
,
new
Runnable
()
{
@Override
public
void
run
()
{
ThreadHelper
.
sleep
(
1000
);
throw
new
CodeException
(
"00"
,
"等待2秒秒"
);
}
},
new
Runnable
()
{
@Override
public
void
run
()
{
ThreadHelper
.
sleep
(
2000
);
throw
new
CodeException
(
"00"
,
"等待2秒秒"
);
}
});
}
@Test
@Test
public
void
test
()
{
public
void
test
()
{
try
{
try
{
RunnableListAuto
.
run
(
new
Runnable
()
{
runTest
(
true
);
@Override
public
void
run
()
{
ThreadHelper
.
sleep
(
1000
);
throw
new
CodeException
(
"00"
,
"等待2秒秒"
);
}
},
new
Runnable
()
{
@Override
public
void
run
()
{
ThreadHelper
.
sleep
(
2000
);
throw
new
CodeException
(
"00"
,
"等待2秒秒"
);
}
});
throw
new
CodeException
(
"没有抛出异常"
);
throw
new
CodeException
(
"没有抛出异常"
);
}
catch
(
Exception
ex
)
{
}
catch
(
Exception
ex
)
{
Log
.
error
(
TestRunnableListAuto
.
class
,
ex
);
//
Log.error(TestRunnableListAuto.class, ex);
}
}
}
}
@Test
public
void
test1
()
{
runTest
(
false
);
}
}
}
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