title: Is there a way to set the target for a task dynamically with the App Engine Java runtime?
body: <p>When enqueuing a background task with the App Engine Python runtime, you can <a href="https://cloud.google.com/appengine/docs/standard/python/taskqueue/push/creating-tasks#specifying_the_worker_service" rel="noreferrer">specify a target for the queue</a> which will send the task to be run on a specific service, version, or instance:</p>
  
  <pre><code>task = taskqueue.add(
      url='/update_counter',
      target='worker',
      params={'amount': amount})
  </code></pre>
  
  <p>Is there a way to do this in Java? The documentation <a href="https://cloud.google.com/appengine/docs/standard/java/taskqueue/push/creating-tasks#specifying_the_worker_service" rel="noreferrer">mentions the <code>target</code> parameter</a> but doesn't show an example of how to use it. The <a href="https://cloud.google.com/appengine/docs/standard/java/javadoc/com/google/appengine/api/taskqueue/Queue.html#add-com.google.appengine.api.taskqueue.TaskOptions-" rel="noreferrer"><code>Queue.add</code></a> method has no option for <code>target</code>. The <a href="https://cloud.google.com/appengine/docs/standard/java/javadoc/com/google/appengine/api/taskqueue/TaskOptions#url-java.lang.String-" rel="noreferrer"><code>TaskOptions</code></a> class doesn't have anything that looks like <code>target</code>, either.</p>
  
  <p><a href="https://stackoverflow.com/questions/39481769/how-to-use-modules-in-google-app-engine-and-add-a-target-to-them-using-task-queu">This question documents how to use the <code>target</code></a>, but the answer is to configure it in <code>queue.xml</code>. I'd like to pick the target at runtime, like Python.</p>