1. D:\sdk\groovy-1.7.2\bin>groovysh
2. Groovy Shell (1.7.2, JVM: 1.6.0_25)
3. Type 'help' or '\h' for help.
4. -------------------------------------------------------------------------------
5. groovy:000> import java.lang.management.*
6. ===> [import java.lang.management.*]
7. groovy:000> tb = ManagementFactory.threadMXBean
8. ===> sun.management.ThreadImpl@9b1670
9. groovy:000> tb.class.methods.name.unique().sort()
10. ===> [dumpAllThreads, equals, findDeadlockedThreads, findMonitorDeadlockedThreads, getAllThreadIds, getClass, getCurrentThreadCpuTime, getCurrentThreadUserTime, getDaemonThreadCount, getPeakThreadCount, getThreadAllocatedBytes, getThreadCount, getThreadCpuTime, getThreadInfo, getThreadUserTime, getTotalStartedThreadCount, hashCode, isCurrentThreadCpuTimeSupported, isObjectMonitorUsageSupported, isSynchronizerUsageSupported, isThreadAllocatedMemoryEnabled, isThreadAllocatedMemorySupported, isThreadContentionMonitoringEnabled, isThreadContentionMonitoringSupported, isThreadCpuTimeEnabled, isThreadCpuTimeSupported, notify, notifyAll, resetPeakThreadCount, setThreadAllocatedMemoryEnabled, setThreadContentionMonitoringEnabled, setThreadCpuTimeEnabled, toString, wait]
11. groovy:000> tb.class.methods.findAll { it.name =~ /Alloc/}.each { println it };
12. null
13. public boolean sun.management.ThreadImpl.isThreadAllocatedMemoryEnabled()
14. public boolean sun.management.ThreadImpl.isThreadAllocatedMemorySupported()
15. public long[] sun.management.ThreadImpl.getThreadAllocatedBytes(long[])
16. public long sun.management.ThreadImpl.getThreadAllocatedBytes(long)
17. public void sun.management.ThreadImpl.setThreadAllocatedMemoryEnabled(boolean)
18. ===> null
19. groovy:000> tb.threadAllocatedMemoryEnabled
20. ===> true
21. groovy:000> tid = Thread.currentThread().id
22. ===> 1
23. groovy:000> tb.getThreadAllocatedBytes(tid)
24. ===> 48106672
25. groovy:000> tb.getThreadAllocatedBytes(tid)
26. ===> 48751520
27. groovy:000> tb.getThreadAllocatedBytes(tid)
28. ===> 49384752
29. groovy:000> tb.getThreadAllocatedBytes(tid)
30. ===> 50086240
31. groovy:000> quit