You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@iotdb.apache.org by Xiangdong Huang <sa...@gmail.com> on 2020/04/01 12:44:26 UTC

Re: [jira] [Created] (IOTDB-573) Construct AbstractIoTDBThread and catch all Exception

Hi,

It is good that you guys place this on the agenda.

Sounds good.  But I still suggest you have a glance at how other systems
do, like [1].

[1]
https://github.com/apache/cassandra/blob/trunk/src/java/org/apache/cassandra/utils/WrappedRunnable.java

Best,
-----------------------------------
Xiangdong Huang
School of Software, Tsinghua University

 黄向东
清华大学 软件学院


Jialin Qiao (Jira) <ji...@apache.org> 于2020年4月1日周三 下午8:26写道:

> Jialin Qiao created IOTDB-573:
> ---------------------------------
>
>              Summary: Construct  AbstractIoTDBThread and catch all
> Exception
>                  Key: IOTDB-573
>                  URL: https://issues.apache.org/jira/browse/IOTDB-573
>              Project: Apache IoTDB
>           Issue Type: Improvement
>           Components: Core/Engine
>             Reporter: Jialin Qiao
>
>
> Hi, in current IoTDB codes, threads are created without any constraints.
> RuntimeExceptions are not caught in the run method. Therefore, we usually
> miss the stack information and only get a NullPointerException in the
> parent thread.
>
>
>
> Therefore, we need a base thread AbstractIoTDBThread that manages all
> threads. In the IoTDBThead, all exceptions are caught and logged. Here is
> an example.
>
>
>
> import java.util.concurrent.Callable;
> import org.slf4j.Logger;
> import org.slf4j.LoggerFactory;
>
> public abstract class AbstractIoTDBThread<T> implements Callable<T> {
>
>  protected Logger logger = null;
>
>  public AbstractIoTDBThread() {
>  initLogger();
>  }
>
>  @Override
>  public T call() throws Exception {
>  try {
>  return internalRun();
>  } catch (Exception e) {
>  logger.error("Meet error in sub thread", e);
>  throw e;
>  }
>  }
>
>  abstract void initLogger();
>
>  abstract T internalRun();
>
> }
>
>
> class MyThread extends AbstractIoTDBThread<Long> {
>
>  @Override
>  void initLogger() {
>  logger = LoggerFactory.getLogger(MyThread.class);
>  }
>
>  @Override
>  Long internalRun() {
>  return 0L;
>  }
> }
>
>
>
> This issue contains two tasks:
>
> (1) Create and enrich AbstractIoTDBThread
>
> (2) Make all threads in IoTDB to extend AbstractIoTDBThread.
>
>
>
> --
> This message was sent by Atlassian Jira
> (v8.3.4#803005)
>