/// <summary>Log the current thread stacks at INFO level.</summary> /// <param name="log">the logger that logs the stack trace</param> /// <param name="title">a descriptive title for the call stacks</param> /// <param name="minInterval">the minimum time from the last</param> public static void LogThreadInfo(Org.Apache.Hadoop.Log log, string title, long minInterval) { bool dumpStack = false; if (log.IsInfoEnabled()) { lock (typeof(ReflectionUtils)) { long now = Time.Now(); if (now - previousLogTime >= minInterval * 1000) { previousLogTime = now; dumpStack = true; } } if (dumpStack) { try { ByteArrayOutputStream buffer = new ByteArrayOutputStream(); PrintThreadInfo(new TextWriter(buffer, false, "UTF-8"), title); log.Info(buffer.ToString(Encoding.Default.Name())); } catch (UnsupportedEncodingException) { } } } }
/// <summary> /// Close the Closeable objects and <b>ignore</b> any /// <see cref="System.IO.IOException"/> /// or /// null pointers. Must only be used for cleanup in exception handlers. /// </summary> /// <param name="log">the log to record problems to at debug level. Can be null.</param> /// <param name="closeables">the objects to close</param> public static void Cleanup(Org.Apache.Hadoop.Log log, params IDisposable[] closeables) { foreach (IDisposable c in closeables) { if (c != null) { try { c.Close(); } catch (IOException e) { if (log != null && log.IsDebugEnabled()) { log.Debug("Exception in closing " + c, e); } } } } }