| Author |
Send response before process is done.
|
Pete Larocque
Greenhorn
Joined: Oct 31, 2005
Posts: 14
|
|
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
Joined: Dec 11, 2004
Posts: 13410
|
|
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.
|
Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
|
 |
Pete Larocque
Greenhorn
Joined: Oct 31, 2005
Posts: 14
|
|
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
Joined: Dec 11, 2004
Posts: 13410
|
|
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
Joined: Oct 31, 2005
Posts: 14
|
|
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
Joined: Dec 11, 2004
Posts: 13410
|
|
|
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
Joined: May 11, 2005
Posts: 144
|
|
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
Joined: Oct 31, 2005
Posts: 14
|
|
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
Joined: May 11, 2005
Posts: 144
|
|
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
Joined: Oct 31, 2005
Posts: 14
|
|
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
Joined: Jul 27, 2006
Posts: 57
|
|
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
|
Studying ...
|
 |
 |
|
|
subject: Send response before process is done.
|
|
|