测试平台
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

72 lines
1.7 KiB

  1. import java.util.HashMap;
  2. import java.util.Map;
  3. /**
  4. *
  5. */
  6. public class JvmMemoryTest {
  7. //声明缓存对象
  8. private static final Map map = new HashMap();
  9. public static void main(String args[]){
  10. try {
  11. Thread.sleep(100000);//给打开visualvm时间
  12. } catch (InterruptedException e) {
  13. e.printStackTrace();
  14. }
  15. //循环添加对象到缓存
  16. for(int i=0; i<1000000;i++){
  17. TestMemory t = new TestMemory();
  18. map.put("key"+i,t);
  19. }
  20. System.out.println("first");
  21. //为dump出堆提供时间
  22. try {
  23. Thread.sleep(10000);
  24. } catch (InterruptedException e) {
  25. e.printStackTrace();
  26. }
  27. for(int i=0; i<1000000;i++){
  28. TestMemory t = new TestMemory();
  29. map.put("key"+i,t);
  30. }
  31. System.out.println("second");
  32. try {
  33. Thread.sleep(10000);
  34. } catch (InterruptedException e) {
  35. e.printStackTrace();
  36. }
  37. for(int i=0; i<3000000;i++){
  38. TestMemory t = new TestMemory();
  39. map.put("key"+i,t);
  40. }
  41. System.out.println("third");
  42. try {
  43. Thread.sleep(10000);
  44. } catch (InterruptedException e) {
  45. e.printStackTrace();
  46. }
  47. for(int i=0; i<4000000;i++){
  48. TestMemory t = new TestMemory();
  49. map.put("key"+i,t);
  50. }
  51. System.out.println("forth");
  52. try {
  53. Thread.sleep(Integer.MAX_VALUE);
  54. } catch (InterruptedException e) {
  55. e.printStackTrace();
  56. }
  57. System.out.println("qqqq");
  58. }
  59. }
  60. /**
  61. *
  62. */
  63. class TestMemory {
  64. }