Docker – Best practice to refresh on building image

Adding the date in docker file so that user can update the data for every change.

FROM 
ENV REFRESHED_AT 2017-1-1
Posted in docker, Programming | Leave a comment

Docker – Subnet address in Ubuntu

$ sudo vi /etc/default/docker

modify the following section.
DOCKER_OPTS=”–bip 192.168.1.1/24″

Posted in docker, Programming | Leave a comment

Java – Spring boot with JAX-RS

Enabling Spring boot to use JAX-RS

https://dzone.com/articles/using-jax-rs-with-spring-boot-instead-of-mvc

http://blog.codeleak.pl/2015/01/getting-started-with-jersey-and-spring.html

Posted in Java, Programming | Leave a comment

Java 9 – useful commands to inspect Module

List modules

$ java --list-modules
$ java --list-modules java.base

Diagnostic module dependencies

$ java -Xdiag:resolver -p mods [module name]/[class package path]
$ jar --file [jar path] --print-module-descriptor
Posted in Java, Programming | Leave a comment

Java 8 – general practice using Optional

0. Never, ever use null for an Optional variable.
1. Optional should be only used as a return value.
: never use it for a field in Class and a method parameter.
never use it in collections

2. Never try to call .get() method on an Optional.
: if it is a situation to get a value, ifPresent, map and orElse() family can solve this problem .

3. Remember Optional is not Serializable.

Note)
Java 9 will introduce the following new method

Optional.stream()
Optional.ifPresentOrElse()
Optional.or()
Posted in Java, Programming | Tagged | Leave a comment

Docker – useful command

$ docker log <container id> // show logs
$ docker port <container id> // show port mapping
$ docker inspect <container id> // inspect container settings
Posted in docker | Tagged | Leave a comment

Java – Task polling example with Java 8

public void completionService(ExecutorService executor) {
    CompletionService<CustomTaskResult> completionService =
        new ExecutorCompletionService<CustomTaskResult>(executor);

    completionService.submit(() => {
        // to something
    });


    Future<CustomTaskResult> future = null
    while ((future = completionService.poll()) != null) {

    	// do something

    }
}
Posted in Java, Programming | Tagged | Leave a comment