1 22 23 24 package com.mchange.v2.lang; 25 26 import com.mchange.v2.log.*; 27 import java.lang.reflect.Method ; 28 29 public final class ThreadUtils 30 { 31 private final static MLogger logger = MLog.getLogger( ThreadUtils.class ); 32 33 final static Method holdsLock; 34 35 static 36 { 37 Method _holdsLock; 38 try 39 { _holdsLock = Thread .class.getMethod("holdsLock", new Class [] { Object .class }); } 40 catch (NoSuchMethodException e) 41 { _holdsLock = null; } 42 43 holdsLock = _holdsLock; 44 } 45 46 public static void enumerateAll( Thread [] threads ) 47 { ThreadGroupUtils.rootThreadGroup().enumerate( threads ); } 48 49 52 public static Boolean reflectiveHoldsLock( Object o ) 53 { 54 try 55 { 56 if (holdsLock == null) 57 return null; 58 else 59 return (Boolean ) holdsLock.invoke( null, new Object [] { o } ); 60 } 61 catch (Exception e) 62 { 63 if ( logger.isLoggable( MLevel.FINER ) ) 64 logger.log( MLevel.FINER, "An Exception occurred while trying to call Thread.holdsLock( ... ) reflectively.", e); 65 return null; 66 } 67 } 68 69 private ThreadUtils() 70 {} 71 } 72 | Popular Tags |