Signal methods are void so we use Query methods to retrieve the result from it ,but it uses global variables .Is there any other way we can get result without global variables

Signal methods are void so we use Query methods to retrieve the result from it ,but it uses global variables .Is there any other way we can get result without global variables.

Can you give more details on what you’re trying to achieve? Secondly what SDK are you using?

I am using JAVA SDK
The use case is where i need to combine 2 post API’s with in a single workflow , So as a single class in temporal cannot have 2 workflow methods, we made a parent class which has a workflow method that waits until two child workflows complete. And in child workflows for both API’s has a workflow methods which basically calls activities and return the result.In the parent workflow there would be two signal methods to take the input from rest api controller and its used to work with activities and obtain result .The only way where we could the result from signal methods is using query method which uses global variables as signal methods are void. Is there any other way we could get the result without using global variables.

Are you trying to wait for two different signals? Something like this should work:

  @WorkflowInterface
  interface MyWorkflow {
    @WorkflowMethod
    void exec();

    @SignalMethod
    void setName(String name);

    @SignalMethod
    void setTitle(String title);

    @QueryMethod
    String queryTitleAndName();
  }

  public static class MyWorkflowImpl implements MyWorkflow {
    private String name;
    private String title;

    @Override
    public void exec() {
      Workflow.await(() -> name != null && title != null);
      //Execute activities and child workflows
    }

    @Override
    public void setName(String name) {
      this.name = name;
    }

    @Override
    public void setTitle(String title) {
      this.title = title;
    }

    @Override
    public String queryTitleAndName() {
      return title + " " + name;
    }
  }


Using global variables is prohibited inside the workflow code. However, you can use instance variables to pass data between signal/query/update handlers and the main workflow thread.

You can use signal-with-start to start workflow lazily when sending a signal.

We are trying to get the result from the workflow and that is set using query methods, but whenever we call this query method in controller it is expecting thread.sleep since the activity is not completed and running in the background to return back, how do i handle this case to get the result back in controller without giving thread.sleep

You can use an update to wait for an activity completion. The update differs from a query in that it can block as long as needed.

I have tried with update method but the app is not up with permission denied: updateworkflow execution operation is disabled on this namespace.
We cannot add frontend.enableUpdateworkflowexecution =true on our app side since we are connecting to the server which is already deployed by some body else and there is no server configuration on our side its just to connect to them

Then, use the signal and then call the query in a loop.

We do have an activity where it can be called multiple times but as you said if we use instance variables to return the values if the activity is completed for the first time the returned result is accurate but whenever it is being called the next time again it would return the previous response as it is not null . How do i handle this case?

Sorry, I don’t understand the scenario. I have a feeling that we mean different things by “activity”.

Hi, Signals and Query methods use instance variables right, workflow is working fine in local but when it is moved to higher environments, we do have concurrent requests hitting , will there be any chance of getting the results messed up since we are using instance variables?

What is “higher environments”?

Workflows don’t belong to any specific process, so they have no " moving " concept. Temporal guarantees that workflow instance variables will have correct values.

Higher env meant to be dev test and production,

I see. Temporal behaves the same in any of these environments.

Will instance variables for query methods can handle concurrent requests, and give accurate results without any conflicts?

Do you have a specific scenario that concerns you? Temporal uses cooperative multithreading, so only one thread runs at a time. Thus no explicit synchronization is needed.

We are working with a singleton java class will the instance variables handle concurrent requests? Is there any other way to get the results from query methods without instances variables ?

What do you mean by “singleton java class”?

What is the business problem you are trying to solve? There is some confusion about how to map your problem to Temporal abstraction.