How to disable JVM large page support

from http://www.oracle.com/technetwork/java/javase/7u51-relnotes-2085002.html

Area: hotspot/gc
Synopsis: Crashes due to failure to allocate large pages.

On Linux, failures when allocating large pages can lead to crashes. When running JDK 7u51 or later versions, the issue can be recognized in two ways:

  • Before the crash happens one or more lines similar to this will have been printed to the log:os::commit_memory(0x00000006b1600000, 352321536, 2097152, 0) failed;
    error='Cannot allocate memory' (errno=12); Cannot allocate large pages, falling back to regular pages
  • If a hs_err file is generated it will contain a line similar to this:Large page allocation failures have occurred 3 times

The problem can be avoided by running with large page support turned off, for example by passing the "-XX:-UseLargePages" option to the java binary.


If you cannot set this on your command line, you can set this value to JAVA_TOOL_OPTIONS environment variable: export JAVA_TOOL_OPTIONS=”-XX:-UseLargePages”

Advertisements

A good post discussing JVM cannot allocate memory (errno=12)

http://bryanmarty.com/2012/01/14/forking-jvm/

To enable over-commit temporarily:

echo 1 > /proc/sys/vm/overcommit_memory

For a more permeant solution, you will need to edit /etc/sysctl.conf and add the following:

vm.overcommit_memory = 1

Now just restart your system for the change to take effect.

Create scheduled task in Spring Boot

Reference: https://spring.io/guides/gs/scheduling-tasks/

pom.xml:

<project xmlns=”http://maven.apache.org/POM/4.0.0&#8243; xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance&#8221;
xsi:schemaLocation=”http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd”&gt;
<modelVersion>4.0.0</modelVersion>

<groupId>com.sample</groupId>
<artifactId>gs-scheduling-tasks</artifactId>
<packaging>jar</packaging>
<version>1.0-SNAPSHOT</version>

<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.2.RELEASE</version>
</parent>

<properties>
<java.version>1.8</java.version>
</properties>

<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>

ScheduledTasks.java

package com.sample;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.util.Date;

/**
* Created by vagrant on 5/25/17.
*/
@Component
public class ScheduledTasks {

private static final Logger log = LoggerFactory.getLogger(ScheduledTasks.class);

private static final SimpleDateFormat dateFormat = new SimpleDateFormat(“HH:mm:ss”);

@Scheduled(fixedRate = 5000)
public void reportCurrentTime() {
log.info(“The time is now {}”, dateFormat.format(new Date()));
}
}

App.java

package com.sample;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.scheduling.annotation.EnableScheduling;

/**
* Hello world!
*
*/
@SpringBootApplication
@EnableScheduling
public class App
{
public static void main( String[] args )
{
SpringApplication.run(App.class);
}
}

To run: mvn spring-boot:run

a script to install basic Java dev tools for Vagrant provision

#! /bin/bash
echo install jdk1.8
wget –no-cookies –no-check-certificate –header “Cookie: oraclelicense=accept-securebackup-cookie” “http://download.oracle.com/otn-pub/java/jdk/8u131-b11/d54c1d3a095b4ff2b6607d096fa80163/jdk-8u131-linux-x64.rpm&#8221;
yum localinstall jdk-8u131-linux-x64.rpm -y
touch /etc/profile.d/java.sh
cat <<EOT >> /etc/profile.d/java.sh
export JAVA_HOME=”/usr/java/jdk1.8.0_131″
export JAVA_PATH=”$JAVA_HOME”
export PATH=”$PATH:$JAVA_HOME”
EOT
rm jdk-8u131-linux-x64.rpm

echo install ant
wget http://www.us.apache.org/dist/ant/binaries/apache-ant-1.10.1-bin.tar.gz
tar xvfz apache-ant-1.10.1-bin.tar.gz -C /opt
ln -s /opt/apache-ant-1.10.1 /opt/ant
sh -c ‘echo ANT_HOME=/opt/ant>>/etc/environment’
ln -s /opt/ant/bin/ant /usr/bin/ant
rm apache-ant-1.10.1-bin.tar.gz

echo install python3.6
yum -y groupinstall development
yum -y install https://centos7.iuscommunity.org/ius-release.rpm
yum -y install python36u python36u-pip python36u-devel
# yum -y install python36u-pip
# yum -y install python36u-devel

echo install Ansible
yum -y install ansible

echo set basic vim style
touch /etc/vimrc
cat <<EOT >> /etc/vimrc
filetype plugin indent on
set tabstop=2
set shiftwidth=2
set expandtab
set softtabstop=2
set nowrap
set number
color blue
EOT

echo install maven
wget http://apache.mirror.gtcomm.net/maven/maven-3/3.5.0/binaries/apache-maven-3.5.0-bin.tar.gz
tar xvf apache-maven-3.5.0-bin.tar.gz -C /usr/local
rm apache-maven-3.5.0-bin.tar.gz
ln -s /usr/local/apache-maven-3.5.0/ /usr/local/maven
touch /etc/profile.d/maven.sh
cat <<EOT >> /etc/profile.d/maven.sh
#! /bin/bash

export M2_HOME=/usr/local/maven
export PATH=$PATH:/usr/local/maven/bin
EOT

su -l vagrant -c “mkdir /home/vagrant/.m2”
touch /home/vagrant/.m2/settings.xml
cat <<EOT >> /home/vagrant/.m2/settings.xml
<settings>
<proxies>
<proxy>
<active>true</active>
<protocol>http</protocol>
<host>localhost</host>
<port>3128</port>
<nonProxyHosts>127.0.0.1</nonProxyHosts>
</proxy>
</proxies>
</settings>
EOT

chown vagrant /home/vagrant/.m2/settings.xml

echo install SDKMAN
yum install -y zip unzip
su -l vagrant -c ‘curl -s “https://get.sdkman.io&#8221; | bash’
su -l vagrant -c ‘source /home/vagrant/.sdkman/bin/sdkman-init.sh’

echo install Spring Boot
su -l vagrant -c ‘sdk install springboot’

echo install Intellij
sudo yum install -y xauth libXtst
wget http://download.jetbrains.com/idea/ideaIC-2017.1.3.tar.gz
tar xvf ideaIC-2017.1.3.tar.gz
mv idea-IC-171.4424.56 /usr/lib
ln -sf /usr/lib/idea-IC-171.4424.56 /usr/lib/idea
ln -sf /usr/lib/idea/bin/idea.sh /usr/bin/idea
sed -i ‘s/Xm\(s\|x\)[[:digit:]]*m/Xmx\12048m/g’ /usr/lib/idea/bin/idea.vmoptions /usr/lib/idea/bin/idea64.vmoptions
sed -i ‘s/ReservedCodeCacheSize=[[:digit:]]*m/ReservedCodeCacheSize=700m/g’ /usr/lib/idea/bin/idea.vmoptions /usr/lib/idea/bin/idea64.vmoptions
sed -i ‘4i -XX:MaxPermSize=512m’ /usr/lib/idea/bin/idea.vmoptions /usr/lib/idea/bin/idea64.vmoptions
cat <<EOT >> /etc
sysctl -p

Sample java application to test using headless selenium server

 

public class App 
{
    private static void googleExampleThatSearchesFor(final String searchString) throws MalformedURLException {
        WebDriver driver =
                new RemoteWebDriver(new URL("http://localhost:4444/wd/hub"), DesiredCapabilities.chrome());
        driver.get("http://www.google.com");
        WebElement searchField = driver.findElement(By.name("q"));
        searchField.sendKeys(searchString);
        System.out.println("Page title is: " + driver.getTitle());
        searchField.submit();

        (new WebDriverWait(driver, 10)).until(new ExpectedCondition<Boolean>() {
            public Boolean apply(WebDriver driverObject) {
                return driverObject.getTitle().toLowerCase().startsWith(searchString.toLowerCase());
            }
        });

        System.out.println("Page title is: " + driver.getTitle());

        driver.quit();
    }
    public static void main( String[] args ) throws Exception{
        googleExampleThatSearchesFor("Cheese!");
    }
}

How to install JDK8 or JDK9 on Ubuntu

from: https://www.digitalocean.com/community/tutorials/how-to-install-java-with-apt-get-on-ubuntu-16-04

  • sudo add-apt-repository ppa:webupd8team/java
  • sudo apt-get update
  • sudo apt-get install oracle-java8-installer
  • sudo update-alternatives –config java

 

From: https://github.com/franzwong/til/blob/master/java/silent-install-oracle-jdk8-ubuntu.md

Silent install Oracle JDK 8 on Ubuntu

Problem: During installation of Oracle JDK 8 on Ubuntu, we need to agree on license agreement manually.

Solution: Installing Java Automatically (With Silent Option)

Shell script:

sudo apt-get install -y python-software-properties debconf-utils
sudo add-apt-repository -y ppa:webupd8team/java
sudo apt-get update
echo "oracle-java8-installer shared/accepted-oracle-license-v1-1 select true" | sudo debconf-set-selections
sudo apt-get install -y oracle-java8-installer

Ansible:

---
- name: Add apt repository
  apt_repository:
      repo: 'ppa:webupd8team/java'
      state: present
      update_cache: yes

- name: Accept license
  debconf:
    name: 'oracle-java8-installer'
    question: 'shared/accepted-oracle-license-v1-1'
    value: 'true'
    vtype: 'select'

- name: Install java
  apt: name={{ item }} state=present
  with_items:
      - oracle-java8-installer
      - ca-certificates
      - oracle-java8-set-default

One to One mapping in hibernate

<hibernate-mapping package=”gar.entity”>

<class name=”RTPRequest” table=”rtp_request”>
<id name=”id” type=”long”>
<column name=”id” />
<generator class=”sequence”>
<param name=”sequence”>seq_rtp_request</param>
<param name=”allocationSize”>1</param>
<param name=”initialValue”>1</param>
</generator>
</id>

<one-to-one name=”garnishment” class=”Garnishment” cascade=”all”></one-to-one>

</class>

</hibernate-mapping>

 

===================================================

<hibernate-mapping package=”gar.entity”>

<class name=”Garnishment” table=”garnishment”>

<id name=”id” type=”long”>
<column name=”id”/>
<generator class=”foreign”>
<param name=”property”>rtpRequest</param>
</generator>
</id>

<one-to-one name=”rtpRequest” class=”RTPRequest” constrained=”true”></one-to-one>

</class>

</hibernate-mapping>