From Passion to Profession
  • Home
  • Notes
  • Projects
  • Resources
    • Discovery Log
    • Books I Read
    • Blogs I Visit
    • Tools I Use
  • Home
  • Notes
  • Projects
  • Resources
    • Discovery Log
    • Books I Read
    • Blogs I Visit
    • Tools I Use

Inversion of Control / Dependency Injection Pattern

3/20/2020

0 Comments

 
People who just started to learn Spring framework is often confused by the term "Inversion of Control" (IoC) which can be achieved through "Dependency Injection" (DI).

DI is a way of providing the dependencies (e.g. creating objects and its dependencies), wiring components into application. In Spring, those objects defined and instantiated by Spring containers then inject into application are called Spring Beans.

IoC is a concept, it means to create instances of dependencies first, the concept is usually achieved by using metadata-driven approach to assemble instances at runtime. IoC is the end result of DI. However, DI is not the only way to achieve IoC. For example, Workday's XpressO is a great example of metadata-driven development to achieve IoC.

Here are some more good explanations:
Inversion of Control (IoC) means to create instances of dependencies first and latter instance of a class (optionally injecting them through constructor), instead of creating an instance of the class first and then the class instance creating instances of dependencies. Thus, inversion of control inverts the flow of control of the program. Instead of the callee controlling the flow of control (while creating dependencies), the caller controls the flow of control of the program.

​~
https://stackoverflow.com/questions/3058/what-is-inversion-of-control
IoC is a programming technique, expressed here in terms of object-oriented programming, in which object coupling is bound at run time by an assembler object and is typically not known at compile time using static analysis.

​~
http://en.wikipedia.org/wiki/Inversion_of_control
IoC is a common pattern in the Java community that helps wire lightweight containers or assemble components from different projects into a cohesive application.
~
http://www.martinfowler.com/articles/injection.html (reworded)
Spring helps in the creation of loosely coupled applications because of Dependency Injection. 

​In Spring, objects define their associations (dependencies) and do not worry about how they will get those dependencies. It is the responsibility of Spring to provide the required dependencies for creating objects.

-https://stackoverflow.com/questions/9403155/what-is-dependency-injection-and-inversion-of-control-in-spring-framework

Read More
0 Comments

Java 1.8 Lambda & Method Reference

2/25/2018

0 Comments

 
One way to create thread is to pass a object that implements Runnable Interface to a Thread constructor as mentioned in Java Multithreading Approaches (Java Concurrency - Part 1):
​public class MyRunnable implements Runnable{
  // this method is called when a runnable thread starts
  public void run(){
    printMessage();
  }
}

public class ThreadDemo{
  public static void main(String args[]){
    Thread t1 = new Thread(new MyRunnable); 
    Thread t2 = new Thread(new MyRunnable);
    Thread t3 = new Thread(new MyRunnable);
    t1.start();    
    t2.start();
    t3.start();

  }

  public static void printMessage(){
    System.out.println("Hello");
  }
}


Read More
0 Comments

Java Collection Framework

9/10/2014

0 Comments

 
Java Collection Framework (java.util.* package) is a unified architecture for representing and manipulating collections. This post is a quick note of my knowledge about Java Collection Framework that covers frequently used java data structure to store a group of elements and/or key-value pairs. In the java.util framework, there are two major camps - Collections & Map.

To illustrate, I use solid lines to denote 'extends', and dash lines to denote 'implements'. The way to use my note is to first go to the diagram looking for the specific class or interface, then read the brief blurb that'll remind you what the class or interface is about for the right data structure.
Picture

Read More
0 Comments

Analyze Heap Dump with Eclipse Memory Analyzer

9/9/2013

0 Comments

 
Ever suspect your Java app leaking memory but not sure which class it is potentially causing OOM? 

In this post, I recommend Eclipse Memory Analyzer (MAT) for developers to analyze heap dumps so you can chase down leak suspects. MAT is much easier to use and read than stand-along jhat unix command, and while monitor memory usage using VisualVM is helpful, MAT gives you specific hints about which classes may be the suspects.

Read More
0 Comments

Monitor Java Application with VisualVM

9/7/2013

0 Comments

 
It is not uncommon that you need to watch the runtime performance of a Java application on a server. In this post, I'll show you how to set up a target JVM so you can monitor its cpu, heap memory, threads usage from a specific JMX client - VisualVM. VisualVM is similar to JConsole, a JMX-compliant monitoring tool, but is more advanced. 


To use a JMX client, the setup you need to do first are:

  1. On the Target server where JVM runs, you need to enable JMX Agent for the JVM.
  2. On the local machine where you want to monitor your Java application from, you need a JMX client. For this post, I chose VisualVM.
  3. To prevent other JMX client from accessing your JMX Agent, you want to turn on authentication when your JMX client connects to your JMX Agent.

Read More
0 Comments

Enable JMX Agent for JVM

9/6/2013

0 Comments

 
With JMX agent enabled for a JVM, you can use a JMX Client (JConsole or VisualVM) to tap into your JVM to monitor its performance and memory usage at runtime. Your java runtime is not enabled with JMX by default unless you explicitly specify to turn it on.

Read More
0 Comments

Non-Blocking Function (Java Concurrency - Part 3)

7/11/2013

0 Comments

 
With regards to java concurrency, when reading some API documentation (e.g. java.util.concurrent),  there's  the term "non-blocking" and "blocking." In computer science, non-blocking means:

  • Use low-level atomic hardware primitives (machine instructions) such as compare-and-set instead of intrinsic locks to ensure thread safety (data integrity under concurrent access).
  • Performance gain and better scalability. threads does not have to be suspended/waken up by the OS using synchronization.
  • Use non-fair locking (which does not guarantee any particular access order), which can have much more system throughput than fair-locking (which grants access to the longest-waiting thread).
  • It doesn't cause other tasks (threads) to wait until the task is finished.
  • Deadlock free. The risk of deadlocks is removed. No one thread will wait to get a lock held by another thread "forever". 

Read More
0 Comments

ForkJoinPool Example (Java Concurrency - Part 2)

7/10/2013

0 Comments

 
In Java concurrency, ForkJoinPool uses a work-stealing multi-threading framework which works well for executing tasks of uneven distribution of chunk sizes. Before you read on, you need to know Java Multithreading Approaches first.

A ForkJoinPool implements ExecutorService but it differs from other (I'll refer them as 'traditional') ExecutorService mainly by virtue of employing work-stealing - all threads in the pool attempt to find and execute subtasks created by other active tasks. It automatically balance the task load between threads, while traditional ThreadPoolExecutor has no mechanism for such kind of load balancing. If no available worker thread is available, tasks will be blocked until a thread becomes available to steal work from those workers who are busy.

Read More
0 Comments

Java Multithreading Approaches (Java Concurrency - Part 1)

7/7/2013

0 Comments

 
In Java concurrency, there are two low level concurrency implementations in Java to create a thread - extend the Thread class or implement Runnable interface.  These basic approaches neither return value from the thread nor throw exception should anything goes wrong. There's a third approach since Java 1.5 - use Java Concurrency package which supports to receive return values from thread execution.

Read More
0 Comments

WeakHashMap Example

7/2/2013

0 Comments

 
Before I go into WeakHashmap, first let's look at different types of reference-object. A reference object encapsulates a reference to some other object. There are different level of reachability of references, from the strongest to the weakest. The weaker the reference, the more likely it is to be thrown away.

Read More
0 Comments
<<Previous

    Categories

    All
    Algorithm
    Concurrency
    CQ
    Data Structure
    Design Pattern
    Developer Tool
    Dynamic Programming
    Entrepreneur
    Functional Programming
    IDE
    Java
    JMX
    Marketing
    Marklogic
    Memory
    OSGI
    Performance
    Product
    Product Management
    Security
    Services
    Sling
    Social Media Programming
    Software Development

    Feed Widget

    Archives

    May 2020
    March 2020
    April 2018
    March 2018
    February 2018
    December 2017
    March 2017
    November 2016
    June 2016
    May 2016
    April 2016
    October 2015
    September 2015
    August 2015
    September 2014
    July 2014
    June 2014
    May 2014
    March 2014
    January 2014
    December 2013
    November 2013
    October 2013
    September 2013
    August 2013
    July 2013
    June 2013

    RSS Feed

in loving memory of my mother  and my 4th aunt
Photos from net_efekt, schani, visnup, Dan Zen, gadl, bobbigmac, Susana López-Urrutia, jwalsh, Philippe Put, michael pollak, oskay, Creative Tools, Violentz, Kyknoord, mobilyazilar