How to use java heap profilers (HPROF) - java

With the basic knowledge of java 'hprof', I tried executing the below command as per oracle docs
java -agentlib:hprof Hello.class
But i get the below error instead of the profiling information
Caused by: java.lang.ClassNotFoundException: Hello.class
at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:252)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:320)
Can someone illustrate on how should hprof be used properly so as to get the profiling information ?

You just need to remove the .class at the end of the class as Java by default will search for class files.
java -agentlib:hprof Hello
However, to get the heap allocation profile you need to add some parameters...
java -agentlib:hprof=heap=sites Hello
For more information type
java -agentlib:hprof=help
And visit http://docs.oracle.com/javase/8/docs/technotes/samples/hprof.html

Related

Jdbc no suitable driver found. Postgresql [duplicate]

Note
I'm running windows, the path just looks like it's linus because I typed it manually and thats how I think of paths.
I'm trying to run a java class That I have built to diagnose my connection to a databse, it references the oracle jdbc adaptor.
When I just run it without a class path:
%> java DBDiagnostics <connectionString>
I get an exception when it reaches the following line of code:
Class.forName("oracle.jdbc.pool.OracleDataSource").newInstance();
with the following exception:
java.lang.ClassNotFoundException: oracle.jdbc.pool.OracleDataSource
at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:252)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:320)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:169)
at DBDiagnostics.GetConnection(DBDiagnostics.java:43)
at DBDiagnostics.runDiagnostic(DBDiagnostics.java:29)
at DBDiagnostics.main(DBDiagnostics.java:18)
Creating connection.
java.sql.SQLException: No suitable driver found for lskd
at java.sql.DriverManager.getConnection(DriverManager.java:602)
at java.sql.DriverManager.getConnection(DriverManager.java:207)
at DBDiagnostics.GetConnection(DBDiagnostics.java:55)
at DBDiagnostics.runDiagnostic(DBDiagnostics.java:29)
at DBDiagnostics.main(DBDiagnostics.java:18)
Veryfying connectivity to Database
Exception in thread "main" java.lang.NullPointerException
at DBDiagnostics.verifyTable(DBDiagnostics.java:86)
at DBDiagnostics.verifyTable(DBDiagnostics.java:76)
at DBDiagnostics.verifyDatabseConnectivity(DBDiagnostics.java:68)
at DBDiagnostics.runDiagnostic(DBDiagnostics.java:36)
at DBDiagnostics.main(DBDiagnostics.java:18)
I assume that this is because I need to include it in the classpath.
So, I tried adding it to the classpath like this:
%> java -classpath .:ojdbc6.jar DBDiagnostics <connectionString>
The VM just says it cant find the class:
Exception in thread "main" java.lang.NoClassDefFoundError: DBDiagnostics
Caused by: java.lang.ClassNotFoundException: DBDiagnostics
at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:252)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:320)
Could not find the main class: DBDiagnostics. Program will exit.
I know this is a question I should just know the answer to, but what am I doing wrong?
Replace the colon with a semicolon:
java -classpath .;ojdbc6.jar DBDiagnostics <connectionString>
is there a typo:
%> java -classpath .:ojdbc6.jar DBDiagnostics <connectionString>
maybe it would work if you type this:
%> java -classpath ./ojdbc6.jar DBDiagnostics <connectionString>
Does the DBDiagnostics.class file appear in the directory from which you're launching Java? If not, the class loader won't find it.
Does the DBDiagnostics class have a package? If it does, you have to refer to the fully resolved class name, and the root of the package hierarchy has to appear in the directory from which you launch Java.
Mike Sickler's answer looks right for a Windows platform. The path separator for Windows is ";", but ":" for Unix and Linux, so make sure you always use the right one!
Long shot, but is this Unix or Windows? If on Windows the class path separator should be a semi colon:-
%> java -classpath .;ojdbc6.jar DBDiagnostics <connectionString>
And of course you need to have the ojdbc6.jar file in the current directory if you don't specify any path to it. (And possibly it's dependencies as well...)

Not able to print GC details

I am trying to print the GC details for a test program in eclipse.I want to set it only for my program so I went to Run>Run Configurations and in VM arguments gave this:
-Xms1024M -Xmx1024M –XX:+PrintGCDetails –XX:+PrintGCTimeStamps
However when I do this and run my program I get the following error:
java.lang.NoClassDefFoundError: –XX:+PrintGCDetails
Caused by: java.lang.ClassNotFoundException: –XX:+PrintGCDetails
at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:252)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:320)
What am I doing wrong in passing the arguments.
What should tip you off is the error message NoClassDefFoundError: –XX:+PrintGCDetails - the JVM isn't trying to parse it as an option but a class...
Then, look at the dashes before -Xms1024M and –XX:+PrintGCDetails / –XX:+PrintGCTimeStamps - they're different!
Replace the latter ones with the former (ie. "real" dashes/minus-sign) and you're good to go.
Cheers,

NoClassDefFoundError from JavaCC generated code

As part of my study, I am using the JavaCC Eclipse plug-in to create a lexical analysis and parser a parser for a programming language.
The parser is generated succesfully and when I run the generated Java code in Eclipse, it is working perfectly.
However, to easily pass a text file to parse, I would like to run the program from command line. When doing so using java Adder with Adder being the name of my main file, I am getting the following error:
Exception in thread "main" java.lang.NoClassDefFoundError: Adder
Caused by: java.lang.ClassNotFoundException: Adder
at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
Can anyone tell me how to fix this error? I have read that I might have to modify my path but I am unsure what to add to the path.
At runtime JVM is not able to find the class in classpath. Please make sure that you include java class in system classpath

running python using jython

I want to run a python function using jython..
Taking the example from this site.
http://sundaycomputing.blogspot.com/2011/01/python-udfs-from-pig-scripts.html
Now when i run the script (pig -f myscript.pig
It returns me this error
Pig Stack Trace
---------------
ERROR 2998: Unhandled internal error. org/python/core/PyException
java.lang.NoClassDefFoundError: org/python/core/PyException
at org.apache.pig.scripting.jython.JythonScriptEngine.registerFunctions(JythonScriptEngine.java:127)
at org.apache.pig.PigServer.registerCode(PigServer.java:567)
at org.apache.pig.tools.grunt.GruntParser.processRegister(GruntParser.java:421)
at org.apache.pig.tools.pigscript.parser.PigScriptParser.parse(PigScriptParser.java:419)
at org.apache.pig.tools.grunt.GruntParser.parseStopOnError(GruntParser.java:188)
at org.apache.pig.tools.grunt.GruntParser.parseStopOnError(GruntParser.java:164)
at org.apache.pig.tools.grunt.Grunt.exec(Grunt.java:81)
at org.apache.pig.Main.run(Main.java:427)
at org.apache.pig.Main.main(Main.java:108)
Caused by: java.lang.ClassNotFoundException: org.python.core.PyException
at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
... 9 more
================================================================================
I am guessing its because of the first line.. REGISTER udf.py USING jython AS udf;
and that I have to specify jython path? (since i am running this code on cluster.. i dont think i have set this thing up)..
Now... since i dont know much of java.. hence switched on python ... but how do i make this code run??
What sort of setup i have to do on my env... to debug this problem.
Thanks
Add $PIG_HOME/lib/jython.jar to your PIG_CLASSPATH environment variable.

Help Executing this Java Application

I received this source code: http://www.sbbic.org/split.zip under the Apache 2.0 License: http://www.apache.org/licenses/LICENSE-2.0
It came to me from the author without documentation or support (the author doesn't have the time right now, he is writing a book). My knowledge of Java is very limited.
Can someone tell me how to run the application in order to split the words in columns.txt file that is included in the source?
I've looked around in TextSegmenter.java trying to find how it should be called on the command line, but I have not been successful.
If I call: java com\whitemagicsoftware\dictionary\TextSegmenter lexicon.csv columns.txt
I get this error:
Exception in thread "main"
java.lang.NoClassDefFoundError:
com\whitemagicsoftwar
e\dictionary\TextSegmenter (wrong
name:
com/whitemagicsoftware/dictionary/TextSe
gmenter)
at java.lang.ClassLoader.defineClass1(Native
Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:620)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:12
4)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:260)
at java.net.URLClassLoader.access$000(URLClassLoader.java:56)
at java.net.URLClassLoader$1.run(URLClassLoader.java:195)
at java.security.AccessController.doPrivileged(Native
Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:276)
at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319)
I tried putting it into a .jar (again with limited experience, I only zipped the files with manually created manifest files included), but it is unable to load.
I am a newbee - sorry if this is a dumb question, but I would appreciate your help!
The purpose of the script is to break words that are joined (ex. "addresstype") into separate words (ex. "address" and "type"). The hope is to use this script in breaking words for the Khmer language which uses no spaces between words.
Thank you!
You are missing external libraries on the CLASSPATH. You have to set the CLASSPATH environment variable, or pass a classpath to the java command via the -cp option, like
java -cp externallib.jar:otherlib.jar -jar myjar.jar

Categories

Resources