0

I created a class which contains only SQL Lite connection's code in java . So here I executed this program in Linux(raspberry-pi) & windows than I observe Linux is taking more memory in comparison of windows

The memory shown below for Linux

  PID USER      PR  NI  VIRT  RES   SHR S  %CPU %MEM    TIME+   COMMAND 
 3337 root      20   0  744m  179m  10m S   0.0 19.4    0:07.79 dbtest.java 

Windows take 18 mb with Connection Code

& here if I comment the Connection's code then it takes less memory

  PID USER      PR  NI  VIRT  RES   SHR S  %CPU %MEM    TIME+   COMMAND 
 3337 root      20   0  596m  17m  10m S   0.0 19.4    0:07.79 dbtest.java 

Windows take 9 mb without Connection Code

I wanna know why Linux is taking quiet memory, if anyone know please look my problem.

package test;

import java.sql.Connection;
import java.sql.DatabaseMetaData;
import java.sql.DriverManager;
import java.sql.SQLException;

public class DBTest {

    public static void main(String[] args) {
        dbtest();
        while (true) {
            try {
                Thread.sleep(20000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }   
    }

    public static boolean dbtest() {
        Connection conn = null;
        try {

            System.out.println("Before ...... Class.forname");
            Class.forName("org.sqlite.JDBC");
            try {
                Thread.sleep(5000);
            } catch (InterruptedException e) {

                e.printStackTrace();
            }
            String dbURL = "jdbc:sqlite:product.db";
            conn = DriverManager.getConnection(dbURL);
            if (conn != null) {
                System.out.println("Connected to the database");
                try {
                    Thread.sleep(5000);
                } catch (InterruptedException e) {

                    e.printStackTrace();
                }
                DatabaseMetaData dm = (DatabaseMetaData) conn.getMetaData();
                System.out.println("Driver name: " + dm.getDriverName());
                System.out.println("Driver version: " + dm.getDriverVersion());
                System.out.println("Product name: "
                        + dm.getDatabaseProductName());
                System.out.println("Product version: "
                        + dm.getDatabaseProductVersion());
            }
        } catch (ClassNotFoundException ex) {
            ex.printStackTrace();
        } catch (SQLException ex) {
            ex.printStackTrace();
        } finally {
            try {
                conn.close();
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }
        return false;
    }  
}
yuvi
  • 79
  • 8
  • which jvm? https://docs.oracle.com/cd/E21764_01/web.1111/e13814/jvm_tuning.htm#PERFM155 And do you use same heap size? http://viralpatel.net/blogs/jvm-java-increase-heap-size-setting-heap-size-jvm-heap/ – HRgiger Nov 23 '15 at 12:09
  • JVM is java 7 & in case of linux it takes 14942208 heap size for windows it takes 123731968 heap size – yuvi Nov 23 '15 at 13:12
  • It means windows is taking more heap size Here my doubt is all about the physical RAM of system Linux takes 179 mb & windows 18 mb – yuvi Nov 23 '15 at 13:16
  • 7 is the version but since java is open source there is different jvms i.e. for linux there is openjdk, oracle jvm etc... Also as you notice they use different heap size, maybe someone will give you a nice answer but I guess its OS dependent and if you set heap size and other JVM parameters manually as environment parameter I believe you will get closer values, anyway there is also different CPU architecture as well that I believe precision will effect memory as well. – HRgiger Nov 23 '15 at 13:23
  • How are you obtaining your Windows memory usages? i.e. how do you know you are comparing apples to apples? – Jonah Graham Nov 23 '15 at 20:44
  • Yes I used open jdk 7(JAVA 7) I used Task Manager in windows & for Linux ps – yuvi Nov 24 '15 at 04:28
  • Can I reduce the Linux memory consumption size for this SQLite Connection's support? – yuvi Nov 24 '15 at 04:32

1 Answers1

0

The short answer is that you can't compare memory usage like that.

There are numerous articles out there about memory usage, I recommend starting with a stack overflow answer: https://stackoverflow.com/a/131346/2796832

Community
  • 1
  • 1
Jonah Graham
  • 7,890
  • 23
  • 55