This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Why this code snippet does not send the msg ? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Why this code snippet does not send the msg ?" Watch "Why this code snippet does not send the msg ?" New topic
Author

Why this code snippet does not send the msg ?

arun mahajan
Ranch Hand

Joined: Dec 07, 2001
Posts: 305
Hello,
I am try with following code snippet..this is suppose to send to another class but surprisingly it sends the first message and don't touch the rest of two? But if i stop the sending part but only prints it does all the activity? Perhaps I am doing something silly...Could not understand what?
Could you please help me?
regards,
Arun

[ April 22, 2002: Message edited by: Dirk Schreckmann ]
arun mahajan
Ranch Hand

Joined: Dec 07, 2001
Posts: 305
Please help me to sort this problem
regards
arun
Rob Ross
Bartender

Joined: Jan 07, 2002
Posts: 2205
It's not clear what your sender class is doing, but the way you describe your problem it seems like it's blocking at construction, ie, calling:
new Sendorder(pr)
is not returning.
What are you doing in your constructor? You should probably re-factor your constructor so that it doesn't perform any blocking activity, and move it to some method invocation that performs the same fucntionality. At least this way, you can construct your object.
Without knowing what the Sendorder constructor is doing, it's hard to say anything more specific.


Rob
SCJP 1.4
arun mahajan
Ranch Hand

Joined: Dec 07, 2001
Posts: 305
Thanks for your reply Rob. please help me to figure out the problem.
Here is the code for sendorder class:

regards,
Arun
[ April 22, 2002: Message edited by: Dirk Schreckmann ]
Rob Ross
Bartender

Joined: Jan 07, 2002
Posts: 2205
What exactly prints out when you run your program? What is the last thing that prints?
DO you know where your code blocks after that? The constructor is empty, so that's not the problem.
What method is causing your problem?
arun mahajan
Ranch Hand

Joined: Dec 07, 2001
Posts: 305
If I stop sending my request to this class it prints out easy..but if open up whole lot of code it sends first message and than hangs up and don't show any thing to me...
Rob do you thing style of coding could be a problem? can i write it better way?
what could be other reasons of this behaviour?
Any thought?
regards,
Arun
Rob Ross
Bartender

Joined: Jan 07, 2002
Posts: 2205
arun,
what prints out? I can't help you if you don't give me specific information.
Can you please print out the exactly contents of your console (ie, Dos Window/command window) so I can see what is getting printed and where the application hangs?
Thank you.
arun mahajan
Ranch Hand

Joined: Dec 07, 2001
Posts: 305
Problem is never sends the error...perhaps there is no error but if I try to debug what I could find is that it never calls the second instance...
I don't know who can help me in this world....
regards,
Arun
[ April 21, 2002: Message edited by: arun mahajan ]
Mike Curwen
Ranch Hand

Joined: Feb 20, 2001
Posts: 3695

You're sending around a PrintWriter object. Do you ever flush this? Is it auto-flushing? If you println() to a buffered object, and something causes the program to 'abort' or 'hang'.. then you won't ever see the output.

Try this (*especially* when you catch exceptions), don't just send to your pr object, but send to System.err.println the same message (the exception you just caught).

System.err.println is not buffered, and you should see the error on your console.

What Rob has been asking you is for the output in your DOS window, and I suspect there hasn't been any, because you are catching every exception and burying it.
arun mahajan
Ranch Hand

Joined: Dec 07, 2001
Posts: 305
Thanks Mike foryou suggestion...I will try to rerun same...but perhaps this won't help as this class is being called by a servlet and Syste.err.println() will not let me to see the error there...

But I would like to ask following question and would appreciate if some one can answer them point wise:-
1. IS it bad idea of catching every exception and burying them their itself...(perhaps sound foolish but what is right?)
2. Am i writing a better code? I am sure there could be better way of writing my sendorder class...can you help me?
3. Is style of coding I am adopting is taking lot of memory?
4. Am i releasing the memory in better fashion?
5. will it be useful to call System.gc() after every call of sending my orders to sendorder class?
Please spare some moments and help me for these basic questions...
regards,
Arun
[ April 21, 2002: Message edited by: arun mahajan ]
arun mahajan
Ranch Hand

Joined: Dec 07, 2001
Posts: 305
Can somebody help me for these basic questions..it may help to sort out my problem..i would be highly obliged
regards,
arun
arun mahajan
Ranch Hand

Joined: Dec 07, 2001
Posts: 305
Please help to answer these basic questions...I could not able to find an answer for my problem but perhaps these question/answer somewhere help...
PLEASE HELP...
regards,
Arun
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Why this code snippet does not send the msg ?
 
Similar Threads
Basic questions...Memory management and all
Why this stand alone app cannot communicate with servlet
Why this error StreamCorruptedException
Why it fails to update record
Why this stand alone app cannot communicate with servlet