HttpURLConnection without waiting

E

ennio

Hi everybody.
I need to connect to a servlet, because i want to send an http request
with some parameters.

This is the code:
URL url = new URL("http://blahblahblah.com.../servlet?var1=value");
HttpURLConnection connection = (HttpURLConnection)
url.openConnection();
connection.getInputStream();

The point is that connection.getInputStream() waits for the for the
whole processed response of the servlet. But i don't want to wait,
because the server-side is a long process and i don't mind about the
output. I just want to send the request.
How can i accomplish that? If i write a raw-socket request, will the
server (tomcat) kill the servlet thread if i close the socket? Do i
really need to write a raw-socket request?
thanks
 
S

su_dang

ennio said:
Hi everybody.
I need to connect to a servlet, because i want to send an http request
with some parameters.

This is the code:
URL url = new URL("http://blahblahblah.com.../servlet?var1=value");
HttpURLConnection connection = (HttpURLConnection)
url.openConnection();
connection.getInputStream();

The point is that connection.getInputStream() waits for the for the
whole processed response of the servlet. But i don't want to wait,
because the server-side is a long process and i don't mind about the
output. I just want to send the request.
How can i accomplish that? If i write a raw-socket request, will the
server (tomcat) kill the servlet thread if i close the socket? Do i
really need to write a raw-socket request?
thanks

On the top of my mind, if you don't care about the output, you can
create a thread and do it from there. Your main thread will not be
blocked.
 
E

ennio

Thank you very much. I was thinking about it too. I was wondering if
it's "okay" to launch threads from a servlet.

(e-mail address removed) ha scritto:
 
A

Andrea Desole

ennio said:
Thank you very much. I was thinking about it too. I was wondering if
it's "okay" to launch threads from a servlet.

yes. Just make sure the thread terminates, or you will have a lot of
threads after some time. Maybe a better solution would be to use one
thread that queues the jobs coming from the servlets called by the users
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,819
Latest member
masterdaster

Latest Threads

Top