• Post Reply Bookmark Topic Watch Topic
  • New Topic

Send response before process is done.

 
Pete Larocque
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Sorry if this as been already answered but I could not find the information.

I have 3 part in my project.
A j2me device
A servlet
A Asp control that send fax.

So I call my servlet with my j2me device, my device wait on the getResponseCode(), my Servlet do the process in the end it call the asp control to send a fax, my servlet wait on the asp control response to finish, and send the response "OK" to my j2me device.

I can't really change the asp control code. but I can assume the service as sent the fax.

All I need is a way to send the response to my j2me device before the fax is actually sent (cuz it take up to a minute) but I can't find how to do it.


Thanks for the help!
Pete
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you spawn a new thread to make the call, you can return immediately while the work is being done in the other thread.

I have an example app that does this at:
http://simple.souther.us/not-so-simple.html
Look for LongRunningProcess.

If you need more help with the particulars of spawning threads, we have a forum dedicated to Threading and Synchronization where some very bright people hang out.
 
Pete Larocque
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the answer, that what I did, but I did it on the j2me device instead, doing it in the servlet would have been the best ( at least i would be sure the data as been saved on the server, then return a "OK", and if the fax don't work just too bad), but I could not get it to work. Seems like the servlet was waiting on the the thread to be done before sending the response back.

Thanks!
[ July 28, 2006: Message edited by: Pete Larocque ]
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Pete Larocque:
... Seems like the servlet was waiting on the the thread to be done before sending the response back.


How are you kicking off the thread?
 
Pete Larocque
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I made a class which implements runnable at that class do is calling the Asp.net service which send the fax.

So I make an instance call the "run", that the last thing my Servlet do, but I never get the "OK" before that thread is done.

Thanks
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is more of a Threading issue than a servlet issue so I'm going to move this to our Threads forum where you will probably receive better advice for writing threading code.
 
Arvind Sampath
Ranch Hand
Posts: 144
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So I make an instance call the "run", that the last thing my Servlet do, but I never get the "OK" before that thread is done.


Think over these questions.

You are invoking the 'run()' method. It is just another java method. Isnt it? Where is the code that spawns a new thread and executes run?

Think over it. If you are still stuck, we'll be more than happy to help you out.


Arvind
 
Pete Larocque
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My guest is make another servlet that does that request, and call that servlet inside a thread ?

Thanks for the suggestions, and thanks moving my thread.
 
Arvind Sampath
Ranch Hand
Posts: 144
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My guest is make another servlet that does that request, and call that servlet inside a thread ?


No Pete. You dont have to do that. You'll achieve nothing by calling another servlet.

There is no problem with your actual approach. The flaw is in the manner in which you invoke your thread.

Okie...Guess you've had enough puzzles and riddles....You said that you invoked the run() method on the Thread. If that is what you actually did, then do change it objThread.start().


Arvind
 
Pete Larocque
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the answer.

I'm going to try that. Sorry i did not fool around more with my code until i get it right knowing i was on the right path, but i'm a little under pressure here

Pete
 
Mateus Lucio
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi folks, i've just started study threads, so i cant be much helpful, but while studing, i found the Callable interface, it enables your thread to return a value, i dont know if it will help you but i guess you should take a look at it
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!