code: @SuppressWarnings("checkstyle:illegalcatch")
    void startTask(final Configuration taskConfig) throws TaskClientCodeException {
  
      synchronized (this.contextLifeCycle) {
  
        if (this.task.isPresent() && this.task.get().hasEnded()) {
          // clean up state
          this.task = Optional.empty();
        }
  
        if (this.task.isPresent()) {
          throw new IllegalStateException("Attempting to start a Task when a Task with id '" +
              this.task.get().getId() + "' is running.");
        }
  
        if (this.childContext.isPresent()) {
          throw new IllegalStateException(
              "Attempting to start a Task on a context that is not the topmost active context");
        }
  
        try {
          final Injector taskInjector = this.contextInjector.forkInjector(taskConfig);
          final TaskRuntime taskRuntime = taskInjector.getInstance(TaskRuntime.class);
          taskRuntime.initialize();
          this.taskRuntimeThread = new Thread(taskRuntime, taskRuntime.getId());
          this.taskRuntimeThread.start();
          this.task = Optional.of(taskRuntime);
          LOG.log(Level.FINEST, "Started task: {0}", taskRuntime.getTaskId());
        } catch (final BindException | InjectionException e) {
          throw new TaskClientCodeException(TaskClientCodeException.getTaskId(taskConfig),
              this.getIdentifier(),
              "Unable to instantiate the new task", e);
        } catch (final Throwable t) {
          throw new TaskClientCodeException(TaskClientCodeException.getTaskId(taskConfig),
              this.getIdentifier(),
              "Unable to start the new task", t);
        }
      }
    }
docs: Launches a Task on this context.
  
  @param taskConfig the configuration to be used for the task.
  @throws org.apache.reef.runtime.common.evaluator.task.TaskClientCodeException If the Task cannot be instantiated
  due to user code / configuration issues.
  @throws IllegalStateException                                                 If this method is called when
  there is either a task or child context already present.