Hi,
I am using the java.net.HttpURLConnection to get the connection to the database. Depend on the input parameter I am getting the result.
Query : if more than one person get the connection with using java.net.HttpURLConnection and sends their inputs at the same time, will they get their respective results. ie, to say is the connection is thread safe??
Please suggest.
Thanks,
Madhu
-
Is java.net.HttpURLConnection thread safe?? (4 messages)
- Posted by: Madhu sudan
- Posted on: February 24 2005 07:34 EST
Threaded Messages (4)
- please elaborate by adrian osullivan on February 24 2005 08:25 EST
- Here is code.... by Madhu sudan on February 28 2005 09:36 EST
-
Hmm by adrian osullivan on March 01 2005 09:38 EST
- regarding HtpURLConnection by Madhu sudan on March 16 2005 01:54 EST
-
Hmm by adrian osullivan on March 01 2005 09:38 EST
- Here is code.... by Madhu sudan on February 28 2005 09:36 EST
-
please elaborate[ Go to top ]
- Posted by: adrian osullivan
- Posted on: February 24 2005 08:25 EST
- in response to Madhu sudan
How are you using the HTTPUrlConnection to get a database connection? Please paste code. -
Here is code....[ Go to top ]
- Posted by: Madhu sudan
- Posted on: February 28 2005 09:36 EST
- in response to adrian osullivan
Thanks for the reply, Osullivan.
Here is the code. Please let me know if you need any more information.
......
......
String myResp="";
BufferedReader br=null;
String myquery= "";
java.net.URL url;
java.net.HttpURLConnection con=null;
try {
url = form the url
//( ie. url = new URL("http://"+Server_name":"+other information);
con = (HttpURLConnection)url.openConnection();
con.setRequestMethod("GET");
con.connect();
if (con.getResponseCode()==HttpURLConnection.HTTP_OK)
{
br= new BufferedReader(new InputStreamReader con.getInputStream()));
String tmp = br.readLine();
while(tmp!=null)
{
myResp=myResp+tmp;
tmp=br.readLine();
}
}
......
...... // populate the response to the data beans.
}catch (Exception e) {
}finally {
br.close();
con.disconnect();
}
......
.......
} -
Hmm[ Go to top ]
- Posted by: adrian osullivan
- Posted on: March 01 2005 09:38 EST
- in response to Madhu sudan
Hi Madhu,
Ok I understand what you are doing now.
I guess the question is really whether URLConnection.connect() is threadsafe, as that is the one that issues the HTTP request. Clearly each of your clients is running as a discreet process, so they don't share any memory segments. So there is not need to worry about thread safety among clients.
So the only other worry would be whether client requests and handled with thread safety on the server. This depends on the database implementation you are using to handle the incoming HTTP requests.
If it is a vendor product, such as Mod-PL/SQL, it can be assumed to be thread-safe in this respect, otherwise it would not be fit for purpose!
If you have developed your own HTTP broker for the database, this may well thread unsafe, for example if you are using Servlets with member variables. -
regarding HtpURLConnection[ Go to top ]
- Posted by: Madhu sudan
- Posted on: March 16 2005 01:54 EST
- in response to adrian osullivan
Thanks for your detailed information, Osullivan.
Thanks,
Madhu