Java

Asynchronous execution with ExecutorService. Runnable, Callable, Future, CountDownLatch.

ExecutorService Build in API, which running of asynchronous tasks makes simple. Create it with factory method from Executors class: Assign a task in one of 3 ways: submit(task) – provide Runnable or Callable task as an argument. Returns Future invokeAny(taskList) – provide collection of Callable tasks. Tries to execute all tasks, returns response from one of successfully executed. invokeAll(taskList) –…

Continue Reading

Java

Java functional interface. Lambda, Consumer, Supplier, Predicate.

Functional interface – an interface with single abstract method. Optionally marked with @FunctionalInterface annotation.   Lambda – functional interface with a method, which receives and returns value   Supplier – function, which does not receive value, but returns one. Mostly used for lazy value generation.   Consumer – function, which receive value, but does not return. Mostly used for side…

Continue Reading

Java

How to use Jetty to run Java web application locally?

Development of enterprise level web applications always cause some extra effort to setup various components locally. For example, if production environment runs big and robust Web Application server, like IBM WebSphere or Oracle WebLogic, you might don’t want to install and run it locally. Either for performance, configuration or licensing obstacles. There is a reasonable alternative to run and debug…

Continue Reading

Java

How to convert HTML to PDF in Java ?

There is so common requirement to generate PDF for some online content or reporting data. Also there is number of ways doing it. For example you could deliver it by leveraging headless browser (like Chrome or an older, already not supported but verified by time – PhantomJs) or use some dedicated back-end library. Differences between the latter are most likely…

Continue Reading

Java

What is a functional interface in Java8? Quick explanation and sample.

Any interface with a single abstract method is a functional interface and its implementation may be treated as lambda expression. It can have only a single functionality. However a functional interface can have unlimited default methods. Note, that default methods have implementation and abstract methods – not. The latter can be only one in functional interface. When defining your own…

Continue Reading