Win a copy of Spring Boot in Practice this week in the Spring forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Liutauras Vilda
  • Henry Wong
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Mikalai Zaikin
  • Himai Minh

A threaded question

 
Ranch Hand
Posts: 61
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I'm hoping that someone can help me. I'm developing with a webservice framework at the moment which allows me to call a method and pass the request String, along with an object which gets populated with data once the response has returned...

Sender.send(requestString, responseObject)

After calling the above method, the executing thread (Lets call it the MAIN thread) can carry on without waiting.

Sometime, a while after calling the above method I want the MAIN thread to wait and do nothing until this object has been populated. When it has been populated with certain parameters I want to continue execution. (Also, I dont have access to the thread which gets created somewhere within the method above)

Regards,
Eurig
 
Bartender
Posts: 1952
7
Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
First, let me get this out of the way, because I really think it needs to be addressed: why are you developing your own webservice framework?
If you are building yet another web service framework as an open-source/commercial alternative to existing frameworks, or just as a "fun little exercise", by all means feel free to ignore me.

However, if you feel you need to roll your own web service framework out of necessity, as part of a larger project, I'm curious about why existing frameworks don't meet your requirements? I'm not really up to speed on the latest developments of every available webservice framework out there, but I know aleast Apache Axis2 offers asynchronous web service support.
 
Ericson James
Ranch Hand
Posts: 61
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Jelle Klap wrote:First, let me get this out of the way, because I really think it needs to be addressed: why are you developing your own webservice framework?
If you are building yet another web service framework as an open-source/commercial alternative to existing frameworks, or just as a "fun little exercise", by all means feel free to ignore me.

However, if you feel you need to roll your own web service framework out of necessity, as part of a larger project, I'm curious about why existing frameworks don't meet your requirements? I'm not really up to speed on the latest developments of every available webservice framework out there, but I know aleast Apache Axis2 offers asynchronous web service support.



I'd rather not go off topic here. If you read correctly, I said I was developing with A web service framework. Axis2 is the framework. I don't want to go into web services here as the question itself is nothing to do with web services and I didn't want to put anyone off from answering the question if they didn't know Axis2 (or web services)
 
Ranch Hand
Posts: 254
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Will something like below work for you?
 
Rancher
Posts: 4253
57
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This sounds like a good job for a CompletionService and a Future, from java.util.concurrent (JDK 5 or later). Use the CompletionService to hand a task off to a thread pool, returning a Future object which will eventually allow you to access the completed object. When you're ready to wait for the object to be available, call the Future's get() method, optionally with a timeout parameter.

Eurig wrote:(Also, I dont have access to the thread which gets created somewhere within the method above


That might be a problem. Do you have access to the code that creates the thread? Or to the code that populates the object? If not, it may be difficult to do this in a thread-safe manner. Or maybe you just meant that your code for the main thread doesn't have a reference to the worker thread? That's not a problem.
 
Ranch Hand
Posts: 225
Eclipse IDE Debian Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I had a nice post written up about how you could do this yourself, then I noticed that javax.xml.ws.Response extends java.util.concurrent.Future. Axis2 implements JAX-WS, so this should be all you need.
 
Jelle Klap
Bartender
Posts: 1952
7
Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Eurig Jones wrote:

Jelle Klap wrote:First, let me get this out of the way, because I really think it needs to be addressed: why are you developing your own webservice framework?
If you are building yet another web service framework as an open-source/commercial alternative to existing frameworks, or just as a "fun little exercise", by all means feel free to ignore me.

However, if you feel you need to roll your own web service framework out of necessity, as part of a larger project, I'm curious about why existing frameworks don't meet your requirements? I'm not really up to speed on the latest developments of every available webservice framework out there, but I know aleast Apache Axis2 offers asynchronous web service support.



I'd rather not go off topic here. If you read correctly, I said I was developing with A web service framework. Axis2 is the framework. I don't want to go into web services here as the question itself is nothing to do with web services and I didn't want to put anyone off from answering the question if they didn't know Axis2 (or web services)



Ah, misread, nevermind then
 
Ericson James
Ranch Hand
Posts: 61
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks everybody,

I used the Completion service as part of the concurrency framework in the end
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic