• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 374
  • Last Modified:

Debugging JAVA code

I am running a java program from eclipse. It is a comparator utility that reads tables from daabases, dumps them to csv on the local machine and then compares the csv files. I use open csv for dumping and csv parsing. While running the code sometime hangs. There are no errors but it just hangs. How do I debug this?
0
PearlJamFanatic
Asked:
PearlJamFanatic
2 Solutions
 
PearlJamFanaticAuthor Commented:
is there a way to know which line of code it is at? I would now when it is stuck from the console.
0
 
for_yanCommented:
I would start  putting System.out.println(...) along the way
in order first to localize  up to which point the code is getting - so that you could at least know the area
where it happens when the program hangs.
0
 
for_yanCommented:
Also check that you don't have anywhere caught but not printed out exceptions - iin all excepton catches put ex.printStackTrace()
0
Cloud Class® Course: Certified Penetration Testing

This CPTE Certified Penetration Testing Engineer course covers everything you need to know about becoming a Certified Penetration Testing Engineer. Career Path: Professional roles include Ethical Hackers, Security Consultants, System Administrators, and Chief Security Officers.

 
PearlJamFanaticAuthor Commented:
Thanks for the responce. Is there some mechanish that can point the current line of code. Something like what we have in a script compiler like vbsedit.
0
 
for_yanCommented:
ex.printStacktrace() wil print the line of the code - but for that you need to have exception
If it really hangs - then it is major problem bacuse this is really unexoected event so you would not expect anything to print you anything
at that moment
0
 
for_yanCommented:
But put printouts first ion the major sections of the prgram, then loclaize more specifgcally, etc.
Also look through the code to make sure that you never have somnething like
catch(Exception ex) {
// nothing here or no printout of any kind here - thiose are things which are very difficult to catch - if you have such situations
// there should always be ex.printStacktrace() within these braces
}
0
 
chaitu chaituCommented:
may be somewhere in your code  it went to infinite loop
0
 
PearlJamFanaticAuthor Commented:
Ye there are no exceptions but whereever i catch I have some print out so I am sure its not that. Isn't there any way the compiler can point the current line of execution. If I can do that then I know where it is at when it's stuck.
0
 
for_yanCommented:
Compiler does keep track of all lines therefore in case of exception it can print it.
But iotherwise you cannot make it print every line as it exceutes.
You can go line by line in debugging environemnet but it is uaully too long process
0
 
for_yanCommented:
I still think you need tio narrow down the area where it happens.
But you say it happns not every time it executes,  but only from time to time?
0
 
for_yanCommented:
I usually put printouts, and I noticed that when I just stare at the code I cannot find anything - as sson as I
start narrowing down, I  rather quickly locate where the issue is.
Is it a very big prorgram ?
0
 
PearlJamFanaticAuthor Commented:
This is what i got when i did a jstack when it got stuck.

J:\>jstack 5536
2011-10-25 13:24:29
Full thread dump Java HotSpot(TM) Client VM (20.1-b02 mixed mode):

"Low Memory Detector" daemon prio=6 tid=0x16b7b000 nid=0x165c runnable [0x000000
00]
   java.lang.Thread.State: RUNNABLE

"C1 CompilerThread0" daemon prio=10 tid=0x16b70400 nid=0x1654 waiting on conditi
on [0x00000000]
   java.lang.Thread.State: RUNNABLE

"JDWP Command Reader" daemon prio=6 tid=0x16b67c00 nid=0x1580 runnable [0x000000
00]
   java.lang.Thread.State: RUNNABLE

"JDWP Event Helper Thread" daemon prio=6 tid=0x16b66000 nid=0x159c runnable [0x0
0000000]
   java.lang.Thread.State: RUNNABLE

"JDWP Transport Listener: dt_socket" daemon prio=6 tid=0x16b63800 nid=0x13e8 run
nable [0x00000000]
   java.lang.Thread.State: RUNNABLE

"Attach Listener" daemon prio=10 tid=0x16b58800 nid=0x10c4 waiting on condition
[0x00000000]
   java.lang.Thread.State: RUNNABLE

"Signal Dispatcher" daemon prio=10 tid=0x16b57000 nid=0x1220 runnable [0x0000000
0]
   java.lang.Thread.State: RUNNABLE

"Finalizer" daemon prio=8 tid=0x16b4a800 nid=0x15c4 in Object.wait() [0x16cbf000
]
   java.lang.Thread.State: WAITING (on object monitor)
        at java.lang.Object.wait(Native Method)
        - waiting on <0x07ee4980> (a java.lang.ref.ReferenceQueue$Lock)
        at java.lang.ref.ReferenceQueue.remove(Unknown Source)
        - locked <0x07ee4980> (a java.lang.ref.ReferenceQueue$Lock)
        at java.lang.ref.ReferenceQueue.remove(Unknown Source)
        at java.lang.ref.Finalizer$FinalizerThread.run(Unknown Source)

"Reference Handler" daemon prio=10 tid=0x16b45c00 nid=0x15bc in Object.wait() [0
x16c6f000]
   java.lang.Thread.State: WAITING (on object monitor)
        at java.lang.Object.wait(Native Method)
        - waiting on <0x07ee49a0> (a java.lang.ref.Reference$Lock)
        at java.lang.Object.wait(Object.java:485)
        at java.lang.ref.Reference$ReferenceHandler.run(Unknown Source)
        - locked <0x07ee49a0> (a java.lang.ref.Reference$Lock)

"main" prio=6 tid=0x003a7400 nid=0x15b8 runnable [0x0090f000]
   java.lang.Thread.State: RUNNABLE
        at java.net.SocketInputStream.socketRead0(Native Method)
        at java.net.SocketInputStream.read(Unknown Source)
        at com.sybase.jdbc2.timedio.RawDbio.reallyRead(RawDbio.java:202)
        at com.sybase.jdbc2.timedio.Dbio.doRead(Dbio.java:243)
        at com.sybase.jdbc2.timedio.InStreamMgr.readIfOwner(InStreamMgr.java:530
)
        at com.sybase.jdbc2.timedio.InStreamMgr.doRead(InStreamMgr.java:272)
        at com.sybase.jdbc2.tds.TdsProtocolContext.getChunk(TdsProtocolContext.j
ava:555)
        at com.sybase.jdbc2.tds.PduInputFormatter.readPacket(PduInputFormatter.j
ava:229)
        at com.sybase.jdbc2.tds.PduInputFormatter.read(PduInputFormatter.java:62
)
        at com.sybase.jdbc2.tds.TdsInputStream.read(TdsInputStream.java:81)
        at com.sybase.jdbc2.tds.TdsInputStream.readUnsignedByte(TdsInputStream.j
ava:114)
        at com.sybase.jdbc2.tds.Tds.nextResult(Tds.java:1710)
        at com.sybase.jdbc2.tds.Tds.getResultSetResult(Tds.java:2320)
        at com.sybase.jdbc2.tds.TdsCursor.open(TdsCursor.java:186)
        at com.sybase.jdbc2.jdbc.SybStatement.executeQuery(SybStatement.java:137
1)
        at com.sybase.jdbc2.jdbc.SybStatement.executeQuery(SybStatement.java:399
)
        at com.fil.im.replicationtester.util.DbUtil.execSQL(DbUtil.java:33)
        at com.fil.im.replicationtester.util.DbUtil.executeQuery(DbUtil.java:93)

        at com.fil.im.replicationtester.util.TableComparator.minMaxValueForTable
(TableComparator.java:283)
        at com.fil.im.replicationtester.util.TableComparator.compareTables(Table
Comparator.java:77)
        at com.fil.im.replicationtester.util.TableComparator.main(TableComparato
r.java:242)

"VM Thread" prio=10 tid=0x16b42000 nid=0x7a4 runnable

"VM Periodic Task Thread" prio=10 tid=0x16b8ec00 nid=0x162c waiting on condition


JNI global references: 3010

Open in new window

0
 
for_yanCommented:
Do you have any threading in your program ?
0
 
PearlJamFanaticAuthor Commented:
There must be some way to print the current line of code. yes, It is fairly large program.
0
 
PearlJamFanaticAuthor Commented:
no threading
0
 
for_yanCommented:
Maybe it is stuck in interaction with databse - waits to get the data from database through network ?

Bu do you have explicit threads - I mean inyour own code?
0
 
for_yanCommented:
Dtabase in my experience (at least Oracle whaich I'm using) sometimes takes very much unpredicatble
amnmount of time.

Good you don;t have threading - with that it may get really complicated.

So you are retiriveing bug chunks of data and somewhere along the road it stops ?

and does it sometimes revive after that or if it is stuck then you need to iterrupt it?

0
 
PearlJamFanaticAuthor Commented:
yes it gets stuck at sometime for some tables. It is unexpected. When it's stuck I have to interrupt and restart it. on restart it may succeed.
0
 
for_yanCommented:
I'm guessing it is related to database
Put printouts around those execution of the query - just  before the staeement with sql
and then befiore the loop through rows and after that loop - maybe you'll find out something
Put time in the printout, so you don't need to monitor and you don't know when itwill happen next time.
 People of course do it wiith logging, but t really does not matter,
simple system.out.println works as well.
0
 
CEHJCommented:
The quickest change you can make, if you can do it, is to change the driver to see if it makes a difference

I would (even if there isn't a problem) using a good logging strategy throughout the app
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now