Java Option

Java Option
//Java option
//Memory max   
-Xmx1300M
 
//Memory min
-Xms1300M
 
//Print cmd line
-XX:+PrintCommandLineFlags
 
// Some info
-XX:+PrintCompilation
 
-XX:+PrintGCDetails
-XX:+PrintGCTimeStamps
-XX:+PrintGCDateStamps
 
 
 
//Head dump
-XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=/home/ 
 
//Thread prio using java.lang.Thread.setPriority()
-XX:+UseThreadPriorities 
-XX:-UseThreadPriorities 
 
 
//Correspondence Java priority and OS priority
-XX:JavaPriority1_To_OSPriority=10 
-XX:JavaPriority2_To_OSPriority=10 
 





Java Option
Java Performance Option
Java Option
 
//GC tuning 1:
 
-XX:+UseSerialGC 
 
//GC tuning 2:
 
-XX:+UseConcMarkSweepGC -XX:+CMSIncrementalMode
 
//Pointer compression :
 
-XXcompressedRefs:enable=true
-XXcompressedRefs:size=32GB
 
 
//On  versions JDK 8u60+, for perf analysis
 
-XX:+PreserveFramePointer





Process args
Process args && Cmd line Interpretor based on HashMap
Process args
    public static HashMap<String, String> processArgs(final String[] args, final HashMap<String, String> paramCmdLine) {
 
	for (int i = 0; i < args.length; i++) {
	    if (args[i].matches("--.*")) {
 
		final String[] argsNameValue = args[i].split("=");
		if (argsNameValue.length == 1) {
		    final String argsName = argsNameValue[0].substring(2);
		    paramCmdLine.put(argsName, null);
		} else if (argsNameValue.length == 2) {
		    final String argsName = argsNameValue[0].substring(2);
		    final String argsValue = argsNameValue[1];
		    paramCmdLine.put(argsName, argsValue);
		} else {
		    System.out.println("Unexpected parameter:" + args[i]); // TICS !JavaLogging3 : error info
		    Runtime.getRuntime().exit(-1);
		}
	    }
	}
	return paramCmdLine;
    }





Http and java
parse web page
Http and java
package test;
 
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;
 
public class Http {
 
    private static InputStream getStream(String address, int timeout) throws MalformedURLException, IOException {
        final URL url = new URL(address);
        final URLConnection urlConnection = url.openConnection();
        urlConnection.setReadTimeout(timeout);
        urlConnection.setConnectTimeout(timeout);
        final InputStream inputStream = urlConnection.getInputStream();
        return inputStream;
    }
 
    public static void main(String[] args) throws IOException {
 
        final InputStream inputStream = getStream("http://test.com", 1000);
        final BufferedReader responseBuffer = new BufferedReader(new InputStreamReader(inputStream));
        String line = "";
        if (responseBuffer.ready()) {
            while (responseBuffer.ready() && line != null) {
                line = responseBuffer.readLine();
                System.out.println(line);
            }
        }
        responseBuffer.close();
        inputStream.close();
    }
}





Mysql and Java
easy way for processing queries in java
Mysql and Java
package test;
 
import java.io.IOException;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Properties;
import java.util.logging.Level;
import java.util.logging.Logger;
 
public class DbManager {
 
    private final String user;
    private final String password;
    private final String host;
    private final String port;
    private final String dbName;
    private final Properties connectionProps;
    private final Connection conn;
 
    public DbManager(final String user, final String password, final String host, final String port, final String dbName ) {
        this.user = user;
        this.password = password;
        this.host = host;
        this.dbName = dbName;
        this.port = port;
        connectionProps = new Properties();
        connectionProps.put("user", user);
        connectionProps.put("password", password);
 
        final String url = "jdbc:mysql://" + host + ":" + port + "/";
        conn = getConnection(url, connectionProps);
 
        if (conn != null) {
            System.out.println("Connected to database " + url);
        }
    }
 
    @Override
    public String toString() {
        return "DbManager [user=" + user + ", password=" + password + ", host=" + host + ", port=" + port + ", dbName=" + dbName + ", connectionProps="
                + connectionProps + ", conn=" + conn + "]";
    }
 
    private static Connection getConnection(final String url, final Properties connectionProps) {
        Connection conn;
        try {
            conn = DriverManager.getConnection(url, connectionProps);
        } catch (SQLException ex) {
            conn = null;
            Logger.getLogger(DbManager.class.getName()).log(Level.SEVERE, null, ex);
        }
        return conn;
    }
 
    public void viewTable(String name) {
        Statement stmt = null;
 
        final String query1 = "SELECT *  FROM " + dbName + "."+name;
        try {
            stmt = conn.createStatement();
            ResultSet rs = stmt.executeQuery(query1);
 
            System.out.println("");
            while (rs.next()) {
                System.out.println("nb "+rs.getMetaData().getColumnCount());
                for (int i=0;i<rs.getMetaData().getColumnCount(); i++)
                {
                    if (rs.getMetaData().getColumnTypeName(i+1).equals("VARCHAR"))
                    {
                        System.out.println(new String( rs.getBytes(i+1)));
                    }
 
                }
            }
            System.out.println("");
        } catch (SQLException e) {
            System.out.println("" + e);
        } finally {
            if (stmt != null) {
                try {
                    stmt.close();
                } catch (SQLException ex) {
                    Logger.getLogger(DbManager.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
        }
    }
 
    public void runUpdate(final String query) {
        Statement stmt = null;
        System.out.println("query : " + query);
        try {
            stmt = conn.createStatement();
            stmt.executeUpdate(query);
 
        } catch (SQLException e) {
            System.out.println("" + e);
        } finally {
            if (stmt != null) {
                try {
                    stmt.close();
                } catch (SQLException ex) {
                    Logger.getLogger(DbManager.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
        }
    }
 
 
 
        public static void main(String[] args) throws IOException {
 
         DbManager db = new DbManager("user", "password", "host", "3306", "db_name");
         db.viewTable("Table_Name");
    }
 
 
}