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
a2e61075
Commit
a2e61075
authored
Dec 05, 2023
by
yanzg
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
修改日志打印功能,打印更加详细的日志
parent
2587f5d7
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
104 additions
and
38 deletions
+104
-38
WeakHashMapFinishTest.java
yzg-util-base/src/test/java/base/WeakHashMapFinishTest.java
+66
-0
WeakHashMapTest.java
yzg-util-base/src/test/java/base/WeakHashMapTest.java
+38
-38
No files found.
yzg-util-base/src/test/java/base/WeakHashMapFinishTest.java
0 → 100644
View file @
a2e61075
//package base;
//
//import com.yanzuoguang.util.exception.CodeException;
//import com.yanzuoguang.util.thread.ThreadHelper;
//import org.junit.Test;
//
//import java.util.Map;
//import java.util.WeakHashMap;
//
//public class WeakHashMapFinishTest {
//
// public static class MyKeyInner {
// @Override
// protected void finalize() throws Throwable {
// System.out.println("MyKeyInner 开始终结");
// }
// }
//
// public static class MyKey implements AutoCloseable {
// private MyKeyInner myKeyInner = new MyKeyInner();
//
// public MyKey() {
// // throw new CodeException("构造异常");
// }
//
// @Override
// protected void finalize() throws Throwable {
// System.out.println("开始终结");
// throw new CodeException("MyKey 终止异常");
// // 数据库连接在关闭;
// }
//
// @Override
// public void close() throws Exception {
// System.out.println("MyKey close");
//
// }
// }
//
// @Test
// public void test() throws InterruptedException {
// Map<MyKey, Integer> map = new WeakHashMap<>();
// test1(map);
// System.out.println(map.size());
// Thread thread = new Thread(new Runnable() {
// @Override
// public void run() {
// while (true) {
// System.gc();
// System.out.println(map.size());
// ThreadHelper.sleep(100);
// }
// }
// });
// thread.start();
// thread.join();
// }
//
// private void test1(Map<MyKey, Integer> map) {
// try (MyKey myKey = new MyKey()) {
// map.put(myKey, 1);
// } catch (Exception e) {
// throw new RuntimeException(e);
// }
// }
//}
yzg-util-base/src/test/java/base/WeakHashMapTest.java
View file @
a2e61075
package
base
;
//
package base;
//
import
com.yanzuoguang.util.thread.ThreadHelper
;
//
import com.yanzuoguang.util.thread.ThreadHelper;
import
org.junit.Test
;
//
import org.junit.Test;
import
sun.misc.GC
;
//
import sun.misc.GC;
//
import
java.util.Map
;
//
import java.util.Map;
import
java.util.WeakHashMap
;
//
import java.util.WeakHashMap;
//
public
class
WeakHashMapTest
{
//
public class WeakHashMapTest {
//
public
static
class
MyKey
{
//
public static class MyKey{
//
}
//
}
//
@Test
//
@Test
public
void
test
()
throws
InterruptedException
{
//
public void test() throws InterruptedException {
Map
<
MyKey
,
Integer
>
map
=
new
WeakHashMap
<>();
//
Map<MyKey,Integer> map = new WeakHashMap<>();
test1
(
map
);
//
test1(map);
System
.
out
.
println
(
map
.
size
());
//
System.out.println(map.size());
Thread
thread
=
new
Thread
(
new
Runnable
()
{
//
Thread thread = new Thread(new Runnable() {
@Override
//
@Override
public
void
run
()
{
//
public void run() {
while
(
true
){
//
while(true){
System
.
gc
();
//
System.gc();
System
.
out
.
println
(
map
.
size
());
//
System.out.println(map.size());
ThreadHelper
.
sleep
(
100
);
//
ThreadHelper.sleep(100);
}
//
}
}
//
}
});
//
});
thread
.
start
();
//
thread.start();
thread
.
join
();
//
thread.join();
}
//
}
//
private
void
test1
(
Map
<
MyKey
,
Integer
>
map
){
//
private void test1(Map<MyKey,Integer> map ){
map
.
put
(
new
MyKey
(),
1
);
//
map.put(new MyKey(),1);
}
//
}
}
//
}
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