Friday, February 8, 2019

Docker remove/compose and push an image


mvn clean install -DskipTests to build the executable jar file to be dockerized.

docker-compose.yml

version: "2" 
services:
    camunda-demo:
        container_name: ordermanager
        build:
            context: ./
            args:
                JAR_FILE: target/ordermanager-0.0.1-SNAPSHOT.jar
                PORT: 8080
            dockerfile: Dockerfile
        image: mschassisdial/camunda-demo:dev
        ports:
            - 8080:8080
        networks:
            - camunda-network
networks:

    camunda-network:
        driver: bridge
 
 
Dockerfile 

FROM openjdk:8-jdk
VOLUME /tmp
ARG JAR_FILEARG PORTARG CONFIGCOPY ${JAR_FILE} app.jar
COPY ${CONFIG} config.properties
ENTRYPOINT ["java","-jar","/app.jar"]
EXPOSE ${PORT}

docker images

REPOSITORY                                 TAG                 IMAGE ID            CREATED             SIZE
mschassisdial/camunda-demo         dev                 b1a0d11f8a8d        3 minutes ago       693MB
mschassisdial/external-service        dev                 d496ef00abfd        2 hours ago           680MB
mschassisdial/ordermanager       dev                 a37c119aa03c        2 hours ago          693MB
mschassisdial/external-service         qa                  b85c41a54ef6        19 hours ago        680MB
mschassisdial/external-service         <none>              748115d11fb6    20 hours ago       680MB
dialcamundabpm/ordermanager   latest              1052ba8d4e08       20 hours ago       693MB
mschassisdial/camunda-demo         qa                  1052ba8d4e08        20 hours ago        693MB
mschassisdial/camunda-demo         <none>              a3e6620465b0        7 days ago        695MB

chown -R admin:admin .

docker image rm mschassisdial/camunda-demo:dev
docker-compose build
docker push mschassisdial/camunda-demo:dev

Thursday, February 7, 2019

Java Multithreading - Threadsafe Counter

https://stackoverflow.com/questions/29883719/java-multithreading-threadsafe-counter

The traditional way to achieve thread synchronization in Java is by the use of synchronized keyword. While it provides a certain basic synchronization, the synchronized keyword is quite rigid in its use. For example, a thread can take a lock only once. Synchronized blocks don’t offer any mechanism of a waiting queue and after the exit of one thread, any thread can take the lock. This could lead to starvation of resources for some other thread for a very long period of time.
Reentrant Locks are provided in Java to provide synchronization with greater flexibility.

What are Reentrant Locks?
The ReentrantLock class implements the Lock interface and provides synchronization to methods while accessing shared resources. The code which manipulates the shared resource is surrounded by calls to lock and unlock method. This gives a lock to the current working thread and blocks all other threads which are trying to take a lock on the shared resource.


public class ThreadsExample implements Runnable {
    static int counter = 1; // a global counter

    static ReentrantLock counterLock = new ReentrantLock(true); // enable fairness policy

    static void incrementCounter(){
        counterLock.lock();

        // Always good practice to enclose locks in a try-finally block
        try{
            System.out.println(Thread.currentThread().getName() + ": " + counter);
            counter++;
        }finally{
             counterLock.unlock();
        }
     }

    @Override
    public void run() {
        while(counter<1000){
            incrementCounter();
        }
    }

    public static void main(String[] args) {
        ThreadsExample te = new ThreadsExample();
        Thread thread1 = new Thread(te);
        Thread thread2 = new Thread(te);

        thread1.start();
        thread2.start();          
    }
}

Tuesday, February 5, 2019

Setting up a Home VPN Server Using Your Raspberry Pi

https://www.sitepoint.com/setting-up-a-home-vpn-using-your-raspberry-pi/

https://www.noip.com/support/knowledgebase/install-ip-duc-onto-raspberry-pi/

When are connections returned to the connection pool with Spring JPA (Hibernate) Entity Manager?



https://stackoverflow.com/questions/27486104/when-are-connections-returned-to-the-connection-pool-with-spring-jpa-hibernate

https://vladmihalcea.com/a-beginners-guide-to-transaction-isolation-levels-in-enterprise-java/

https://vladmihalcea.com/the-anatomy-of-connection-pooling/