Monday, 26 August 2019

lambda expressions are not supported in -source 1.5 eclipse

Use below in your pom.xml

  <properties>
      <java.version>1.8</java.version>
      <maven.compiler.target>1.8</maven.compiler.target>
      <maven.compiler.source>1.8</maven.compiler.source>

  </properties>



or


<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.2</version>
            <configuration>
                <source>1.8</source>
                <target>1.8</target>
            </configuration>
        </plugin>
    </plugins>
<build>

Monday, 27 May 2019

/proc/cpuifo and /proc/meminfo

physical id     : 1 --> i.e. physical cpu number
siblings        : 8 --> total cores near
core id         : 7 --> my core id
cpu cores       : 8 --> total cores in this CPU



 cat /proc/meminfo
MemTotal:       16264672 kB
MemFree:        15244520 kB
MemAvailable:   15423132 kB

16 GB

free -g
[test@sandeep-20ne ~]$ free -g
              total        used        free      shared  buff/cache   available
Mem:             15           0          14           0           0          14
15 GB

 

Tuesday, 21 May 2019

Thread dump analysis


Healthy thread:

WAITING for request


java.lang.Thread.State: RUNNABLE

runnable


BAD threads

:

java.lang.Thread.State: BLOCKED (on object monitor) : waiting for monitor entry



Oks

java.lang.Thread.State: TIMED_WAITING (parking) :waiting on condition


java.lang.Thread.State: TIMED_WAITING (on object monitor) :Object.wait()


java.lang.Thread.State: TIMED_WAITING (sleeping) :waiting on condition



Thread dump analysis :
1.  Search for BAD threads , Blocked states etc
2. determine the pattern
   like if all of them are waiting for some object<Object_ID> will be printed in stack trace, search with that key.

3. If many threads are waiting for one one specific object,
    do a seach "locked <<Object_Id>>

   you will find, which thread is holding that objects lock.

4. Analyse the stack trace (always bottom up) of that culprit thread.
5. See what is the last step that culprit thread execute (top line of thread)

 If last steps, where this thread was blocked, relates to some JVM related things, like parsing XML, loading some class, logging or reading some file.
Its typically relates to excessive use of Heap, heap running out of memory.

Like some threads "Stuck/Bloacked" in "init" space, that means, they are not able to get the memory they wants, hence the operation is stuck..

CONCLUSION

In such cases, now you need to analyse you heap dump, to see if there are enough space, memory leak etc.


Source
 Java Thread ID ex: tid=0x000000011e52a800 ** This is the Java Thread Id obtained via java.lang.Thread.getId() and usually implemented as an auto-incrementing long 1..n*



 

Wednesday, 17 April 2019

Classpath | JAVA HOME | Classnotfound | main class not found


In window CMD,

1. When we type any commands, lets say "javac", How CMD will know, where exactly is this tool is located, you may type this in any directory, if you type this command, being inside the directiry where it resides, then it will work, else CMD will not know, where to look for.

Ans:

If you want "sandeep" to be recognized as cmd command by window, then you need to tell where to look for sandeep to window

Windows --> Set environment path --> add variable ,




Now I added "C:\..\jdk\bin\,  exact located path , till "bin", now i can type any tool under, which is under that bin folder, window will recognize it as tool, because, that folder in in the path to look for list of window, Sp the "javac" command will work anywhere in the cmd,



Compile time error:

No class found , No main found


How javac <file.java> performs search

How java <classname> performs search

I have "Test.java" and "Test.class", whose package is -->
package kafka.test.com.kafka_test;

Under this folder(its a maven project)

C:\Users\s.jaisawal\workspace\kafka-test\src\main\java\kafka\test\com\kafka_test

But when I go inside this directory via cmd, and run

C:\Users\s.jaisawal\workspace\kafka-test\src\main\java\kafka\test\com\kafka_test>java Test
Error: Could not find or load main class Test


C:\Users\s.jaisawal\workspace\kafka-test\src\main\java\kafka\test\com\kafka_test>
java kafka.test.com.kafka_test.Test
Error: Could not find or load main class kafka.test.com.kafka_test.Test

So I went back to a directory where package starts ,
C:\Users\s.jaisawal\workspace\kafka-test\src\main\java> java Test
Error: Could not find or load main class Test

Finally , from the start of package directory, I gave fully qualified name of my class

C:\Users\s.jaisawal\workspace\kafka-test\src\main\java>java kafka.test.com.kafka_test.Test
Main is running.....


So how does java seaches the classes while loading or executing ?


How a jar is run, how main in jar is found, why -classpath is used while running  a jar ?


Problem with maven eclipse project


Normal java eclipse project, you can right click on java file and "run as application", eclipse compiles and looks for main and runs, but in maven project,

You have to clean and install the pom.xml and then you can run any java (with main), each modification requires a clean build.


======================Problem with Eclipse ====================================

Issue: Project --> Build , doesn't build anything it show no output, 

Cause: 
Make sure that you create a Java project and that your Java files are in
a source folder of that project.



=============Compile your single java file =======================================

1. In linux/window, find a folder where all jar files are present, typeically ../lib/ and include those lib folders in your class path 


javac -cp /home//lib/*: <java_File_name>.java

Similarly, you can include all different libs type directory with : separated in -cp



 

Error: Could not find or load main class


Tuesday, 16 April 2019

Create a maven project | eclipse | kafka


In eclipse --> new --> project --> Maven --> Maven project

provide some default groupid and artifact name , ex:

<groupId>kafka.test.com</groupId>

<artifactId>kafka-test</artifactId>

<version>0.0.1-SNAPSHOT</version>

<packaging>jar</packaging>



finish --> edit po.xml --> add your dependencies, save, it should download all dependencies in to

packages --> maven dependencies

now you can use all the java classes in to your project