Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

server returned HTTP response code 500

Status
Not open for further replies.
the only way i know is to use a try catch block...

Known is handfull, Unknown is worldfull
 
500 is an internal server error. Check the server is up, and the URL is valid.
 
hi there;

actually i am doing java multi-thread app that send params using HttpURLConnection to the servlet.

i am spawning 3 threads.

sometime out of these 3 thread, only 1 or 2 is successfully runing. the another one will the error.

i am sure the servlet is up and the url is valid.
 
Hi,

Are you sure that the values that you post are in sequence to the servlet ? What I am trying to tell is, there could be a chance that before completing the process of one request it might be receiving another request which might be closing the connection or the objects have been initialized and killing the servlet. Just make sure.

Let me know,

Cheers
Venu
 
Dear Venu;

ok, i am really appreciate for ur reply, hope u will keep response for my doubt and question.

let me explain about a little. b4 i am implementing multithread for my java app, i was doing single thread communication between my java app and the servlet. that was running fine w/o the server 500 error. (here, i am sure my header and param etc are correctly sending to the servlet)

since there are many transaction to be sending to the servlet, my boss ask me to implement runnable (thread) in my java app.

at first i only spawning 3 threads. meaning there are only allow 3 thread to run simultaneously. one of the thread completed, main thread will spawn a new process and keep going on.

so my problem (the server return 500) occur here.

well i am really getting confuse here. i havent discover what is going wrong here. seems like my thread program or the server cause the error. i think i better put a little logic of my java app. here.

first of all, i have modify my original java app program. b4 i modify my class to implement runnable it was running fine coz it is sequentially pass the header + param to the servlet. below are the skeleton:

url = new URL("
// loop for each of LocCd
for (int h=0; h<vLocCd.size(); h++) {

// loop for each of RepID
for (int i=0; i<vRepID.size(); i++) {

// Create a URL pointing to the servlet or CGI script and open an HttpURLConnection on that URL

HttpURLConnection con = (HttpURLConnection) url.openConnection();

I said sequentially pass to the SERVLET because it first will loop for the vLocCd (Branch) and then for each of the vLocCd it will loop again for the vRepID (The report type) and send to the SERVLET.

well, in this case, it running fine, w/o receiving the error 500 code.

AFTER THAT, (currently) / now, i have modified this class to implement runnable. i spawn thread for the vLocCd (Branch) and each of the branch will perform as below the loop for each of Report Type

// loop for each of RepID
for (int i=0; i<vRepID.size(); i++) {

REASON: i wantto generate the report faster instead of waiting 1 branch complete then only go for the next branch.

since there are 5 branches at this moment, i started w/ spawning 3 branch and after one of the branch completed spawn the next on and go on. well w/ this new class, as i said 5 threads, some time 2 or 3 will receive the error code 500.

i even DEBUG my new program to spawn only 1 thread at the time. also AGAIN sometime it will return the error code 500.

where is wrong? i think must be my thread program written wrongly?? how come spawn a single thread also return the error code 500. pls help....
 
The URL your Thread trys to access using the URLConnection ( - is that on the same servlet container as your original request that spwned the Thread ?

I would put a stuff-load of debug in your &quot;/jsp/RPTServlet&quot;, and watch the logs for your servlet container.
 
Hi,

I accept with the sebj suggestion of putting lot of debugs statements in the servlet and watch the logs in the servlet container. If we find the problem is in the servlet the we can think of a solution at the servelt level on how to handeling the request one after the other.

I think the servlet that is causing the problem.

Cheers,
venu



 
hi there;

i am hope u all still able to catch up about this topic. sorry for delaying for too many days. i was on other application few days back.

well, this morning, when i am back to my thread program. i have found out something interesting.

first of all, i would like to describe again my current program workflow in order to give a clearer picture.

---java thread program---

*** main thread will spawn this child process ***

1.
db connection

2.

// Create a URL pointing to the servlet or CGI script and open an HttpURLConnection on that URL

url = new URL(&quot;HttpURLConnection con = (HttpURLConnection) url.openConnection();

// loop for each of RepID
for (int i=0; i<vRepID.size(); i++) {

[ do insert random id for verification in servlet ]

// pass parameter after get from db to servlet
}

---java thread program---

---java servlet program---

1.

create instance of other class like db connection and report creation

2.

*** in doGet() method ***

a) get all the parameters

b) get db conn here again

c) [ do delete random id for verification ]

d) if successful
proceed to report creation
else
return some error msg

---java servlet program---

Alright, i have done many types of testing.

[1] Testing w/ spawning TOTAL 3 threads simultaneously by generating (all) the reports. (if one of the thread complete, the next thread will be started)
[2] Testing w/ spawning TOTAL 2 threads simultaneously by generating (all) the reports. (if one of the thread complete, the next thread will be started)
[3] Testing w/ spawning TOTAL 1 threads at the time by generating (all) the reports. (if one of the thread complete, the next thread will be started)
[4] Testing w/ spawning TOTAL 1 threads at the time by generating (1) report. (if one of the thread complete, the next thread will be started)

***from test 1-4, some times out of 5 threads (branches), 2 or 3 will receive the server 500 error code.

***error which i printed out from catalina.out
@sql error = 17008 | java.sql.SQLException: Closed Connection
@sql error = 17009 | java.sql.SQLException: Closed Statement

[5] Testing w/ spawning TOTAL 1 threads at the time by generating (1 or more) reports. (if one of the thread complete, the next thread will NOT started)

***test [5] never receive any error after running for multiple times.

FINALLY, i take out the [insertion and deletion random id for verification from the servlet]. now it able to run with NO server 500 error from test [1 - 5].

well, the server 500 error is getting from the servlet because one of this thread must have close the db conn while other thread try to do the [DELETION from db for verification part]

now, my java thread app able to run w/o receiving the server 500 error code. it also able to generate all the reports for all the branches.

however, there are still some minor error which is printed in catalina.out

** sql error = 17008 | java.sql.SQLException: Closed Connection
** sql error = java.lang.NullPointerException QRY: SELECT RPTDESCR FROM SWREP WHERE RPTID = 004

i tried to run this sql from TOAD or SQLPLUS, it does give error but showing the result. i guess this must because of the db conn is closed while some other thread which is running trying to execute the command.

well, it doesnt effect the output report creation and just that i dunno how to avoid from this error.

am i clarify it clearly enough?

Thanks.

rgd/ yoke yew
 
Well, from that, I think it seems quite conclusive that your threads are dying because of errors in the JDBC step.

Your error 500 is an &quot;internal server error&quot; - which ties up with this. Especially since you say from sqlplus, you get errors !

To fix the problem, forget all the servlet part, and concentrate on the JDBC step. Write a small app that replicates you JDBC stuff, and spawn lots of threads. Work on it till all threads run successfully. One thought is that maybe your threads are trying to concurrently access the same connection object ? If this is the case, the results would not be good ! Make sure that this is not the case, and then also put debug in every time you touch a Connection object - print out the isClosed() method also, as a Connection can often be non-null, but closed - whichcould be the problem.

If you are not using connection pooling, I would suggest using it ...
 
i am sorry there, typo error.

1) refer to my first oct 2 reply, the sqlplus DOESNT show the error. and i have make sure all my sql are valid. i have tested it before implement this program.

2) refer to my first oct 2 reply , the last 4 line, again another typo error :
&quot;well, it DOES effect the output report creation and just that i dunno how to avoid from this error.&quot;

some of the report generated, doesnt show up the date, some doesnt show page, some doesnt show subtiltle and etc.

well, i have highlighted there, after i remove [DELETION from db for verification part] in servlet, i never receive any server 500 error code.

but some time receive

** sql error = 17008 | java.sql.SQLException: Closed Connection
** sql error = java.lang.NullPointerException QRY: SELECT RPTDESCR FROM SWREP WHERE RPTID = 004


RGD/ YOKE YEW
 
well, whatever the typo's... did you read my points about your Connection objects, pooling etc etc ?
 
Hi,

Sedj, asnwer is the one you should look for. But I have question are u opening a new connection for every request and closing it once the process is done? I tink you should be use only one connection and using it.

I had a similar problem were in I used to receive 100's of requests for a same URL at a time. What I did was I have written a schedular and its a thread. All it does is it has a LinkedList, when ever a servlet receives a request it adds the request to the List and Schedular will process the request one after the other.Connection is create very first time when a request is received and uses it there after.

May be this will help you and I am sure you are very much familar with Threads.

Cheers,
-Venu
 
hi;

yes, venur are right, for every request from the servlet, it will open new connection and close when it process done.

ok, i have debug, the close db connection is happened at other class (DBobj) that instantiate by this servlet.

so one thread (branch) will process 5 report say for example, it will do open and close for 5 times. sometime, for one thread, inside there might have 1 or more report that doesnt generate completely because due the sql execution fail (the close connection error). HOW TO FIX THIS?

well, now i planned to do like this. from my java app, when i spawn a thread and open connection there, until the thread done completely, then only close the connection. the problem is like this.

** my java app located at
/home/swx/otps/report/GenerateReport.java

using HttpURLConnection to post the param to servlet that located at
/home/rhb/jspAdm/WEB-INF/classes/RPTServlet.java plus *.servlet files

how to open the dbconn from GenerateReport.java and pass to my RPTServlet.java?

or how to do connection pool? pls give some comments, thanks.

rgd/ yoke yew
 
Hi,

Does your servlet doesn't have access to the DB? what exactily does your Servlet do ?

Cheers,
-enu
 
hi there;

i am glad to hear from u so soon. i am running my java app and servlet at the linux servlet using oracle db and tomcat.

***DBobj.java is a class that contains method to do db conn and sql query.


***Main Thread
/home/swx/otps/report/GenerateReport.java

1. create instance of DBojb.java as db
2. get all the branches + report id from database
3. spawn thread by calling TBranch.
tb = new TBranch(vRepID, (String) vLocCd.elementAt(g), vs, db);

***Child Thread
/home/swx/otps/report/TBranch.java

url = new URL(&quot;// loop for each of RepID
for (int i=0; i<vRepID.size(); i++) {
HttpURLConnection con = (HttpURLConnection) url.openConnection();
parms = &quot;destype=&quot;+DESTYPE+&quot;&desformat=&quot;.......
con.setRequestMethod(&quot;POST&quot;);
.....
.....
}

*** Servlet Get Param
/home/rhb/jspAdm/WEB-INF/classes/RPTServlet.java

doGet() {

1. get params
2. create instance of DBojb.java as db
3. open db connection
4. create instance of SWDBojb and pass db object to SWDBobj constructor
public SWdbobj(DBobj db) {
this.db = db;
}
-- SWDBobj contains all the sql query to Generate Report
-- many select statement here
....
....

5.close db connection

}

----------------------------

i believe u can see the structure now.

so one thread (branch) will generate 5 reports say for example. so it will go to RPTServlet doGet() for 5 times (meaning open and close connection for 5 times also).

the error sometime i received like :
--DBobj.java - doQuery(str) : sql error = 17008 | java.sql.SQLException: Closed Connection
--sql error = java.lang.NullPointerException QRY: SELECT RPTDESCR FROM SWREP WHERE RPTID = 001

sometime, for one thread, inside there might have 1 or more report that doesnt generate completely because due the sql execution fail (the close connection error). HOW TO FIX THIS? any closer solution?

thanks again.

rgd/ yoke yew
 
Hi,

Did you try making SWdbobj(DBobj db) method synchronized?

Is the close db connection() closing this.db.close() or is it closing the global connection object ?

Just make sure.. the best way is put as many debug statements as you can so that we can pin point the problem.

Let me know..

Cheers,
-Venu



 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top