• Post Reply Bookmark Topic Watch Topic
  • New Topic

return a result and carry on  RSS feed

 
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi all

can someone tell me how i can achiev this?

i want to create a server-side method that returns a result to a client app, and then carries on with some processing,

i don't want the Client app to wait for the processing to finish before it gets a result.

eg.

public static String returnResult()
{
return "got it";

// carry on and do some other processing e.g get data from a database
}


Do i use threads? if so how do i use them?

thanks for your help
 
author and iconoclast
Sheriff
Posts: 24217
38
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, you use Threads. Here is a good place to start.
 
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If "server-side" means a Servlet container or some custom server, making your own thread is simple and good.

If you're in an EJB container you're not supposed to make your own threads. Sending a message to a message driven bean via JMS is an approved way to kick off an operation on another thread. It's fairly complex to configure but works very nicely.
 
dale conn
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yes server-side is a servlet container

the Client is a separate App.

I've created a method that connects with a database gathers some data, uses JDOM and writes the results to an xml file and saves that file to the server - this takes a while, so I don't want the Client hanging around for it to finish


So, if the Client calls the method i just want to return to the Client a simple message e.g. "ProcessingFile", the Client can carry on with it's other stuff and the server-side code can carry on with creating the XML file and save it on the server

I don't want the Client to have to wait for the file to be processed before it can carry on

Is this possible?

thanks for any help
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yup, easy peasy.

Note that ThingThatDoesTheRealWork implements Runnable, which requires it to have a run() method, which does the real work. Try the Sun tutorial Ernest recommended and you'll be threading in no time.

Going off topic ... I liked the way you phrased the original topic. I think it's the OO REXX language that has "early return x" which transparently runs any following lines on a new thread. I thought "early return" was a cool concept.
[ June 23, 2006: Message edited by: Stan James ]
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!