code: @Override
      public void execute() throws ActivityException {
          Long instanceId = null;  // pre-existing instanceId
          String instanceIdSpec = getInstanceIdVariable();
          if (instanceIdSpec != null) {
              Object value = getValue(instanceIdSpec);
              if (value instanceof Long)
                  instanceId = (Long) value;
              else if (value != null)
                  instanceId = Long.parseLong(value.toString());
          }
          try {
              if (instanceId == null) {
                  TaskInstance taskInstance = createTaskInstance();
                  instanceId = taskInstance.getTaskInstanceId();
                  if (instanceIdSpec != null)
                      setValue(instanceIdSpec, instanceId);
              }
              else {
                  // update secondary owner
                  updateOwningTransition(instanceId);
              }
  
              String taskInstCorrelationId = TaskAttributeConstant.TASK_CORRELATION_ID_PREFIX + instanceId;
              super.loginfo("Task instance created - ID " + instanceId);
              if (this.needSuspend()) {
                  getEngine().createEventWaitInstance(
                          this.getActivityInstanceId(),
                          taskInstCorrelationId,
                          EventType.EVENTNAME_FINISH, true, true);
                  EventWaitInstance received = registerWaitEvents(false,true);
                  if (received!=null)
                          resume(getExternalEventInstanceDetails(received.getMessageDocumentId()),
                                           received.getCompletionCode());
              }
          } catch (Exception e) {
              throw new ActivityException(-1, e.getMessage(), e);
          }
      }
docs: Creates a task instance unless the INSTANCE_ID_VAR attribute points
  to a pre-existing instance.  If the attribute is populated but the variable
  value is null, the variable will be set to the newly-created instanceId.