7 Replies - 1123 Views - Last Post: 12 September 2010 - 07:47 AM Rate Topic: -----

#1 wissy   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 30-September 09

Thread Dump using divide by zero

Posted 11 September 2010 - 11:32 AM

For my class we have to get a thread dump and the recommended code is using divide by zero. I wrote the below code but did not really know what else I needed to do. From what I have read about thread dumps, you need to have a program that is running while you do the dump and this one does not take long to run. Can anyone tell me what I need to do for this to work?

import java.lang.*;
public class Main {
    public static void main(String[] args) {
         
        try {
            int i = 7/0;
            } catch (java.lang.ArithmeticException e) 
            {
               System.out.println("Illegal Operation.");
            }
        }
    }



Is This A Good Question/Topic? 0
  • +

Replies To: Thread Dump using divide by zero

#2 guido-granobles   User is offline

  • D.I.C Addict
  • member icon

Reputation: 171
  • View blog
  • Posts: 617
  • Joined: 02-December 09

Re: Thread Dump using divide by zero

Posted 11 September 2010 - 12:00 PM

I am not sure about what you want. Do you want trigger a thread dump within your own program ? or do you want trigger a deadlock in your program and then generate a thread dump from other tool in order to analyze the problem.
Was This Post Helpful? 0
  • +
  • -

#3 wissy   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 30-September 09

Re: Thread Dump using divide by zero

Posted 11 September 2010 - 12:07 PM

I believe what we are supposed to do is generate a thread dump from the program but I could not find how.
Was This Post Helpful? 0
  • +
  • -

#4 guido-granobles   User is offline

  • D.I.C Addict
  • member icon

Reputation: 171
  • View blog
  • Posts: 617
  • Joined: 02-December 09

Re: Thread Dump using divide by zero

Posted 11 September 2010 - 12:40 PM

You will have to use the JVMTI. But you will have write it in native code. This means that you will have to use JNI.
Was This Post Helpful? 0
  • +
  • -

#5 Nasm   User is offline

  • New D.I.C Head

Reputation: 27
  • View blog
  • Posts: 47
  • Joined: 10-June 10

Re: Thread Dump using divide by zero

Posted 11 September 2010 - 12:55 PM

I think he want to see the Stack Trace sometimes also called Thread-Dump.
If this is the case the problem is that you catch the error and then print a custom message instead you could do:
try{
int i = 7/0;
}
catch(Exception e){
e.printStackTrace();
}


Or simply throw it further:
public static void main(String... args) throws Exception{
int i = 7/0;
}

Was This Post Helpful? 1
  • +
  • -

#6 guido-granobles   User is offline

  • D.I.C Addict
  • member icon

Reputation: 171
  • View blog
  • Posts: 617
  • Joined: 02-December 09

Re: Thread Dump using divide by zero

Posted 11 September 2010 - 01:04 PM

View PostNasm, on 11 September 2010 - 11:55 AM, said:

I think he want to see the Stack Trace sometimes also called Thread-Dump.
If this is the case the problem is that you catch the error and then print a custom message instead you could do:
try{
int i = 7/0;
}
catch(Exception e){
e.printStackTrace();
}


Or simply throw it further:
public static void main(String... args) throws Exception{
int i = 7/0;
}


Well I was thinking in server debugging. But if it just to see the stack trace of the current thread that is absolutely true. :smile2:
Was This Post Helpful? 1
  • +
  • -

#7 macosxnerd101   User is online

  • Games, Graphs, and Auctions
  • member icon




Reputation: 12361
  • View blog
  • Posts: 45,476
  • Joined: 27-December 08

Re: Thread Dump using divide by zero

Posted 11 September 2010 - 02:00 PM

View PostNasm, on 11 September 2010 - 03:55 PM, said:

I think he want to see the Stack Trace sometimes also called Thread-Dump.
If this is the case the problem is that you catch the error and then print a custom message instead you could do:
try{
int i = 7/0;
}
catch(Exception e){
e.printStackTrace();
}


Or simply throw it further:
public static void main(String... args) throws Exception{
int i = 7/0;
}

That only gives the Stack trace for the Exception. If you want the Stack trace(s), you should look at the Thread class getStackTrace() and getAllStackTraces methods.
Was This Post Helpful? 1
  • +
  • -

#8 wissy   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 30-September 09

Re: Thread Dump using divide by zero

Posted 12 September 2010 - 07:47 AM

Thanks for all the help. I will look over what you put and try to implement it.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1