Commit a2e61075 authored by yanzg's avatar yanzg

修改日志打印功能,打印更加详细的日志

parent 2587f5d7
//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);
// }
// }
//}
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);
} // }
} //}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment