Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

make one method wait for result of other method  RSS feed

 
mi go
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have one servlet having void service method that publishes MQTT msg to broker and servlet contains msgArrived function as followsusing MTQTT paho library)


now i want to get this received msg and transfer it to another servlet as response which is making this servlet a request. But service method of this servlet ends before it receives a msg from broker hence it is transferring null response . How can we acheive this. can we use synchronize method somehow so that service method of this servlet waits for the response from broker and then send response to another servlet.
 
Jeanne Boyarsky
author & internet detective
Sheriff
Posts: 37241
519
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Queue/message are intended to be asynchronous because they take some time. A better approach would be to use an AJAX call on your web page to check if it is done and then redirect to another page. This also lets you show progress.

Alternatively, you change the code to not use the queue.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!