• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Tim Cooke
  • Devaka Cooray
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
Bartenders:
  • Carey Brown
  • Roland Mueller

Thread behaviour

 
Ranch Hand
Posts: 75
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Bartender
Posts: 4179
22
IntelliJ IDE Python Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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

 
Geetha Gubendran
Ranch Hand
Posts: 75
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
This looks like a job for .... legal tender! It says so right in this tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic