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 _log.error("Unable to process runnable: " + e.getMessage());
048
049 _throwable = e;
050 }
051 finally {
052 if (_log.isInfoEnabled()) {
053 _log.info(
054 "Completed processing runnable " +
055 ClassUtil.getClassName(this) + " in " +
056 (System.currentTimeMillis() - start) + "ms");
057 }
058 }
059 }
060
061 protected abstract void doRun() throws Exception;
062
063 private static Log _log = LogFactoryUtil.getLog(
064 ThrowableAwareRunnable.class);
065
066 private Throwable _throwable;
067
068 }