GeeCON Prague 2014*
The moose likes Threads and Synchronization and the fly likes Thread behaviour Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Threads and Synchronization
Bookmark "Thread behaviour" Watch "Thread behaviour" New topic
Author

Thread behaviour

Raj Shan
Ranch Hand

Joined: Sep 04, 2006
Posts: 65
I have a question with Java threads. If someone helps me out with it, that would be of great help to me.

I have a java code in the following sequence.

try {
servlet call (url call) to external application which makes database calls to its own database schema tables;
check the status of the url call;
if status is ok; continue;
do some database insert or update or delete to table1;
} catch (Exception e) {
some log stmnt;
call logError();
}

logError() {
try {
some log stmnt;
insert / update to table2;
update to table3; (the record is there in table3 for sure for update)
} catch (Exception e) {
some log stmnt;
}
}

Just have a look at the above pseudo code. I have 5 threads running to execute the above stmnts. I have several log stmnts in between. The insert request to table1 is given. somewhere something has happened. I could see no log stmnts in the log file. I could find that the servlet call was successful (bcos the external application has successfully inserted the record in the database) after that I have no clue on what has happened. But I could see that update to table3 is successful. I really dont have the idea of what happened to the insert / update to table 2 and the insert stmnt to table 1. But the insert to table1 didnt happen.

Can somebody help me out with what might have happened? Thanks
Steve Luke
Bartender

Joined: Jan 28, 2003
Posts: 4181
    
  21

It is impossible to say what happens with the information you provided. You will have to provided better logging schemes to determine what is happening.

Before we can help you will have to find out specifically what exception is happening and when, and what values you are attempting to insert into the db. Check your logs and if they don't tell you what you need then do a better job of collecting the exception information and printing the results to a log file in a manner that can't fail.

All we know is that somewhere in this code:


Something happens. It is impossible to say now because you only catch the general Exception (which is usually a bad idea). So you catch some exception that occurred either before or while the insert to table1 was happening. The result is the catch code gets executed:

So what happens with the log statements? What do they tell you? Then you call the logError() method, so this code happens:

Some more log statements, what do they say in your log files? You get an insert/update to table2, which you don't see, but the update to table3 does succeed. So what happens to the update to table2? It must succeed for the update to table3 to occur. So if you aren't seeing the results in the table2 then one of your assumptions are incorrect. Maybe you are inserting a null value, or maybe you are not calling the update to table2 when you think you are.

Originally posted by Raj Shan:
I have a question with Java threads. If someone helps me out with it, that would be of great help to me.

I have a java code in the following sequence.

try {
servlet call (url call) to external application which makes database calls to its own database schema tables;
check the status of the url call;
if status is ok; continue;
do some database insert or update or delete to table1;
} catch (Exception e) {
some log stmnt;
call logError();
}

logError() {
try {
some log stmnt;
insert / update to table2;
update to table3; (the record is there in table3 for sure for update)
} catch (Exception e) {
some log stmnt;
}
}

Just have a look at the above pseudo code. I have 5 threads running to execute the above stmnts. I have several log stmnts in between. The insert request to table1 is given. somewhere something has happened. I could see no log stmnts in the log file. I could find that the servlet call was successful (bcos the external application has successfully inserted the record in the database) after that I have no clue on what has happened. But I could see that update to table3 is successful. I really dont have the idea of what happened to the insert / update to table 2 and the insert stmnt to table 1. But the insert to table1 didnt happen.

Can somebody help me out with what might have happened? Thanks


Steve
Raj Shan
Ranch Hand

Joined: Sep 04, 2006
Posts: 65
Thanks for your information. Its not my code. It is someone else code. I am supporting it. We are rewriting it now. But I got the prod issue with the current code. That's why I have written the pseudo code of it. I know that its a bad idea to catch general exception. and the log statements (using log4j) are there in the code but these people don't maintain any log file though which is a very very bad idea. Okay since I couldn't find out anything with that code. Just want to make sure that I didn't miss anything before sending out the reply to the analysis request, I posted the same in the javaranch. Thanks.
 
GeeCON Prague 2014
 
subject: Thread behaviour