001
014
015 package com.liferay.portal.kernel.concurrent;
016
017 import com.liferay.portal.kernel.log.Log;
018 import com.liferay.portal.kernel.log.LogFactoryUtil;
019 import com.liferay.portal.kernel.util.ClassUtil;
020
021
024 public abstract class ThrowableAwareRunnable implements Runnable {
025
026 public Throwable getThrowable() {
027 return _throwable;
028 }
029
030 public boolean hasException() {
031 return (_throwable != null);
032 }
033
034 @Override
035 public void run() {
036 long start = System.currentTimeMillis();
037
038 try {
039 if (_log.isInfoEnabled()) {
040 _log.info(
041 "Processing runnable " + ClassUtil.getClassName(this));
042 }
043
044 doRun();
045 }
046 catch (Exception e) {
047 if (_log.isDebugEnabled()) {
048 _log.debug("Unable to process runnable", e);
049 }
050
051 _throwable = e;
052 }
053 finally {
054 if (_log.isInfoEnabled()) {
055 _log.info(
056 "Completed processing runnable " +
057 ClassUtil.getClassName(this) + " in " +
058 (System.currentTimeMillis() - start) + "ms");
059 }
060 }
061 }
062
063 protected abstract void doRun() throws Exception;
064
065 private static Log _log = LogFactoryUtil.getLog(
066 ThrowableAwareRunnable.class);
067
068 private Throwable _throwable;
069
070 }