我们整天看那些讲JVM的技术文章,看来看去总感觉很抽象,感觉有点虚。我们可以用jconsole简单并真实的感受一下。
package com.company; import com.company.model.Bank; public class Main { public static void main(String[] args) { // write your code here final Bank bank=new Bank(); Thread tadd=new Thread(new Runnable() { @Override public void run() { // TODO Auto-generated method stub while(true){ try { Thread.sleep(1000); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } bank.addMoney(100); bank.lookMoney(); System.out.println("\n"); } } }); Thread tsub = new Thread(new Runnable() { @Override public void run() { // TODO Auto-generated method stub while(true){ bank.subMoney(100); bank.lookMoney(); System.out.println("\n"); try { Thread.sleep(1000); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } }); tsub.start(); tadd.start(); } }
原文:https://www.cnblogs.com/personblog/p/14831649.html