Adam Bien's Weblog

Counting Lines With Java 8

import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;

Path path = Paths.get("./readme.txt");
long lineCount = Files.lines(path).count();

See you at Java EE Workshops at Munich Airport, Terminal 2 or Virtual Dedicated Workshops / consulting

Summer Workshops: From Java EE 7 Bootstrap and Effective Java EE 7 to Java EE 7 Architectures


A book about rethinking Java EE Patterns

A Java EE 7 Startup: Virtualizing Services with

Could you please briefly introduce and yourself?

My name is Wojciech Ozga. I am 25 years old, living currently in Krakow, Poland. I am interested in different areas of Computer Science, starting from software engineering going through computer networks and finishing on cloud computing and linux system administration.

I started my adventure with programming when I was kid, I got Microsoft Visual Basic 6 Pack from my father. Then I was experimenting mostly with c/c++ till 2004 when I entered the path of PHP. After one year I finished works on, one of the first online booking system of apartments in Poland.

Since 2009 I have spent most of my time in the JVM world with small exceptions for python and shell scripting languages. In mid 2012 I started the design and the implementation of I decided to keep as close as possible to Java EE stack, and it was good ;) is a global web platform for virtualization of services like: accommodation, tours, transportation, medical treatments etc. Complex system logic is hidden behind user friendly web page with modern and fresh design.

What makes stand out from other booking platforms is the ability of its users to advertise, promote, find and book a wide range of services in one place. Main features are:

  • selling own services
  • buying services of other users
  • affiliation
  • automatic booking settlements (with anti-fraud protection)
  • reviews

You told me, you read the book and used the ideas to implement a prototype. What is exact the story behind?

I started to take a deeper look into Java EE on my studies. We had classes where outdated ways of coding and usage of Java EE were introduced to students. That time I was thinking that programming in Java EE is a nightmare. I found some online tutorials to give it a try and I remember one which scared me a lot.

The simple code was surrounded by all the patters coming from "old j2ee times". I had to write the same thing 3 times, encapsulating everything. Moreover I was shown to use ale the xml configurations which I just had to "click and fill" in Eclipse. I was really happy passing the exam and being able to forget about Java EE world. But then I found your books. I read two of them: "Real World Java EE Patterns - Rethinking Best Practices" and "Real World Java EE Night Hacks". The second one made so big impression on me that I decided to give it a try implementing the first prototype version of "cloud market" (the antecedent name of What I liked the most reading them is that they are written from the programmer point of view: keep it simple, stupid, do not repeat your self. Skip the unnecessary boiler code, write it the simple way so every one can understand. Some times I had an impression that you are more agile then Agile :) Since that time I recommended them to few friends of mine. I think it is obligatory to read them!

You also told me that your colleague was fascinated by the simplicity of the code and wanted to join forces with you. Could you tell the story to the readers?

One friend of mine - Mateusz Krzyszton - was working previously in a big company as JSF programmer. They had a lot of issues with it, large views and server was responding slowly. They were implementing a lot of hacks to make it work. I needed someone to take care of implementing the front-end part, and I knew Mateusz is a brilliant, experienced programmer. That time we met in Lisbon. I told him the basic idea and I showed the very early mock-ups. He was not convinced. Months later we met again in Warsaw where I showed him the skeleton of the web project, implemented in JSF 2.0 with Primefaces and Omnifaces. He browsed through the source code, looked at the implementation of business logic and he decided to reinforce the team! He was really impressed about, how things can be easily done using modern version of Java EE and JSF following patterns from your books.

What surprised you in Java EE the most?

What I like the most is avoiding of writing the boiler code again and again. At the beginning I created few classes, I wrote few lines of code and I added annotations. The very simple, but working, 3 layer application has been implemented! With no magic I had a simple CRUD application with MySQL engine behind! Every programmer with a bit of experience in linux administration can quickly make business application accessible to everyone in a very easy way.

On the other hand I was really disappointed about the security models. I could not find any suitable for I read official Oracle tutorials 20 times and I did not find JASS as a good solutions for modern web applications. I took a deep look into Apache Shiro but it did not convinced me neither. Modern web systems require much more complex management of roles and permissions. I hope that it will be done with Java EE 8.

What about the Java EE performance? Did you have to perform particular measures to improve the performance?

Performance! Yes, we did several measurements, using JMeter, Selenium and VisualVM. We found few issues but they were mostly related to our implementation. We focused also on the memory usage of our front-end application. I can say that creating complex views, with many components and ajax is not a way to go with JSF. Between requests, JSF stores the component tree of views on the server. Depending on configuration, JSF can store even few hundreds views per user. Having views build with many components we can finish up with few Mb of memory taken by an individual user. That made us thinking about the number of users we can handle during the duration of the user session.

For now we did not find important issues related to the JPA performance, but in the business logic we avoid eagerly loading of collections.

What were the most interesting challenges?

Designing from scratch was really interesting challenge :) Considering the principles, the design of the database was a really difficult part. I needed a good common schema to store information about services like apartments, tours, dentist treatments and many more. All of those services had to be represented in a similar way to allow design of the algorithm to calculate availability and prices.

Probably the most difficult part of the implementation was the business component responsible for service order and booking management.

Moreover I was really excited discovering Amazon Cloud. Two years ago, together with Jose Java EE Coarasa Perez (blog, @coarasa, LinkedIn), we build one of the biggest implementation of cloud using OpenStack on CMS farm (one of the experiments at CERN) It was a great adventure but after using Amazon services I see how immature OpenStack was that time.

Which IDEs / tools are you using?

At the beginning of my Java EE journey I was using Eclipse. It was a nightmare. After reading your books I switched to NetBeans and I was really happy. Things were just working! Right now I am using IDEA IntelliJ. We use maven and Nexus to store artifacts. For continuous integration server we have Jenkins. The application runs on WildFly 8.2. We also use the relational database: MySQL. is hosted in Amazon Cloud. We use EC2 to run VMs, S3 to provide common storage for all VMs and RDS for the database. CloudFront helps us to make our static resources easily accessible around Europe and US.

If you had the chance to start-over, would you use Java EE again?

Definitely yes. I could rethink the usage of JSF for that kind of application, but the business logic would be definitely implemented in Java EE.

Do you have any other (secret) startup ideas, which you would like to share with the readers? :-)

I was asked to implement the idea of a simple web page, where people can see the map with different trails indicating interesting points in the city, related to some topics. User can select the trail, search for places, and select specific marker to read details. This is the classical CRUD application. I decided to implement it with Java EE 7 and it took me one day. It runs on WildFly on some really small server (1gb of memory), waiting for a better times - some investor to push it forward.

Any web links / resources?

  • - virtual market of "real world services". Register your service and start earning money with us ;)
  • Szlaki miejskie - urban trails, application implemented in 1 day using Java EE 7 and Wildfly

Wojciech, thank you for the interview and good luck with your next project!

Summer Workshops: From Java EE 7 Bootstrap and Effective Java EE 7 to Java EE 7 Architectures


A book about rethinking Java EE Patterns

Enterprise Nashorn--Free Article

The Enterprise Nashorn article presents Nashorn features beyond standard (ECMAScript-262 Edition 5.1) JavaScript capabilities. From embedding in Java code and Bean Validation, to operating system task automation, hot deployment and implementation of Java interfaces with JavaScript.

See also Playing With Nashorn screencast.

Feedback is, as always, highly appreciated.

See you at Java EE Workshops at Munich Airport, Terminal 2 or Virtual Dedicated Workshops / consulting

Summer Workshops: From Java EE 7 Bootstrap and Effective Java EE 7 to Java EE 7 Architectures


A book about rethinking Java EE Patterns

March's Airhacks Live Event Shifts to Tuesday

Caused by the massive amount of easter eggs, the March Airhacks Live event is going to shift one day from Monday 6 P.M. CET to Tuesday, 7th April 2015, 6 P.M. CET (subscribe).

This time you get one day more to prepare lots of questions.

Also checkout past episodes--lots of questions were already answered.

See you at Java EE Workshops at Munich Airport, Terminal 2 or Virtual Dedicated Workshops / consulting

Summer Workshops: From Java EE 7 Bootstrap and Effective Java EE 7 to Java EE 7 Architectures


A book about rethinking Java EE Patterns

Playing With Nashorn Scripting Features

Nashorn is shipped with Java 8 and can be used as a system scripting language with seamless Java integration.

One of the killer features is the IDE support. In contrary to batch files or shell scripts, Nashorn is JavaScript (ECMA-262, edition 5.1) and is supported in the IDE with syntax highlighting, code-completion and direct integration with Java ecosystem. Even executable native system scripts can be easily debugged:

Static Page Generator (SPG) is another example of executable Nashorn script example.

See also other screencasts at: or subscribe to

See you at Java EE Workshops at Munich Airport, Terminal 2, particularly at HTML 5 for Java Developers or Virtual Dedicated Workshops / consulting

Summer Workshops: From Java EE 7 Bootstrap and Effective Java EE 7 to Java EE 7 Architectures


A book about rethinking Java EE Patterns

Installing Oracle JDBC-Driver On Wildfly / JBoss

  1. Download the driver: ojdbc[VERSION].jar
  2. Create subfolders [WILDFLY_HOME]/modules/system/layers/base/com/oracle/main/
  3. Copy the downloaded ojdbc[VERSION].jar into the freshly created folder
  4. Create a file module.xml, in the same folder as above, with the contents:
    <module xmlns="urn:jboss:module:1.1" name="">
        <resource-root path="ojdbc[VERSION].jar"/>
        <module name="javax.api"/>
        <module name="javax.transaction.api"/>
  5. In the configuration file standalone.xml add the entry:
    <driver name="oracle" module="">
    within the <drivers> tag.
  6. Add a datasource definition within the <datasources> tag (next to ExampleDS):
    <datasource jndi-name="java:/[NAME]" pool-name="OracleDS" enabled="true">
      <driver>oracle[has to match the driver name]</driver>

Now enjoy the simplicity of Java EE :-)

See you at Java EE Workshops at Munich Airport, Terminal 2 or Virtual Dedicated Workshops / consulting

Summer Workshops: From Java EE 7 Bootstrap and Effective Java EE 7 to Java EE 7 Architectures


A book about rethinking Java EE Patterns

A Java EE Startup: Fashion with Stylight

Interview with Anselm Bauer, STYLIGHT co-founder, passionate Java EE developer and alumni:

Anselm, please briefly introduce yourself

Hi, I’m Anselm, co-founder of STYLIGHT and computer scientist. I live in the best city in the world, Munich, and I have the chance to work in the best team I imaginable. I am a passionate musician, love sports, and nature.

What is and how did it start?

STYLIGHT is the place to discover and shop fashion you love from the best online stores. I founded the company together with three friends in 2008 as students. Currently STYLIGHT employs over 150 people across three offices (Munich, London, and New York).

You’re a co-founder and your development skills are impressive, how important is it for management to technically understand the developers?

The founders of STYLIGHT have backgrounds in economics, electrical engineering, business administration, and computer science. We know that success is only possible when all disciplines work together to reach their goals, that is why appreciation is one of our three core values. We don’t have an engineering department anymore at STYLIGHT, but instead have cross-functional teams, in which engineers work together with marketing, design, sales etc.

How many developers are working on the application?

We have about 30 developers currently working at STYLIGHT. They are distributed over multiple teams along our value chain to create cross-functional teams with the maximum of autonomy and flexibility.

The UI is completely rendered on the server, why?

To guarantee a great experience and performance across all browsers, devices and networks we currently render most of the UI on the server. In addition, most search engines are still not doing a good job at crawling one page applications yet. We like the concept and use it for internal tools, though, together with JS frameworks like Angular.

How many users per day visit the website? What were the peak transactions / second value?

Over six million people visit STYLIGHT every month and find their favourite fashion items. We normally see huge peaks during our TV campaigns.

Which hardware / infrastructure are you using?

Parts of our infrastructure are hosted at a local provider in Munich but the majority of servers are at AWS. We currently migrate all of our infrastructure to AWS to be more flexible and use their great services. We love docker for local development environments as well as for our production deploys.

Is Java EE fast enough for a popular website?

A lot of popular websites use the power of the JVM even if the don’t use Java as a language. We use Java EE features mainly for our business logic where it relieves us from thinking about things like transactions, concurrency etc. Since a lot of our content is a static catalog we can cache a lot of our pages.

Your started straight with the Java EE stack. Was it a good decision?

I think the Java EE stack today is not comparable to the J2EE technologies that were around when we started, and are actually much better than the reputation it has. Back then the amount of boilerplate code was much higher and a script language stack like RoR would have done the trick as well. Today I am glad to use the power of the JVM and the features of Java EE.

Is Java EE productive enough for a startup?

The learning curve is still steeper and we are still fighting against long compile cycles, so for rapid prototyping I may chose something else. In the long run, I think we benefitted from the robustness.

The monitoring capabilities of your system were impressive. What is monitored? Does monitoring pay off?

We monitor servers and applications with several tools and metrics. We use, for example, datadog for general server monitoring, loggly for exceptions, requests, load times etc, and new relic for everything else. Monitoring definitely pays off in finding errors and bottlenecks but also opportunities for refactoring.

We met for the first time at Have you got any ideas for simplification during the workshops?

Definitely. I got a lot of food for thought, especially regarding the testing of Java EE applications and simple patterns like the Entity Control Boundary Pattern.

You recently migrated to Java 8, Java EE 7. How hard was the migration?

We migrated to Java 8, Java EE 7 and are running on the new Wildfly application server. The migration was fairly easy, we did not have to change more than a hundred lines of code.

How much code could you delete during the migration?

We are deleting code iteratively, to avoid a big bang release. But especially for features like asynchronous behaviour we were able to delete a lot of code.

Did you had the chance to chat with other airhacks attendees? If yes, what was the most interesting project / application / problem?

It’s always interesting to see companies from totally different industries like stock exchange and logistics and how they deal with their problems.

If you could start over, would you choose Java EE again?

That is a very difficult question, since it depends very much on the domain I would start something. Although I like working with Java EE, I’m still a computer scientist and I would maybe choose something else, only out of curiosity.

I'm constantly asked by my clients, whether I know any Java EE developers. Are you also looking for passionate Java EE hackers?

Definitely, we currently have open positions for Java EE developers, specialists for RESTful APIs and search technologies on our jobs page

Anselm, thank you for the interview!

Summer Workshops: From Java EE 7 Bootstrap and Effective Java EE 7 to Java EE 7 Architectures


A book about rethinking Java EE Patterns

The Porcupine Spy v0.0.4 and Porcupine v0.0.4 Released

Version 0.0.4 of porcupine is available:


This version comes with minor bug fixes and improvements and a single major feature: the minQueueCapacity statistic. It is the "lowest watermark" of the queue capacity and an early indicator of thread pool overloading / upcoming rejections.

The new attribute is available from method Statistics#getMinQueueCapacity()

porcupine-spy was also released with the same version:


You can use the above dependency instead of the regular porcupine. The porcupine-spy extension injects automatically the statistics to the HTTP headers of all JAX-RS resources.

All requests are going to be extended with the x-porcupine-statistics-[THREADPOOL_NAME] HTTP header:

x-porcupine-statistics-light: {"pipelineName":"light","activeThreadCount":1,
Content-Type: text/plain
Date: Wed, 18 Mar 2015 07:50:20 GMT

Porcupine comes without any additional external dependencies and fully relies on Java EE 7 / Java 8 what makes it lean. Both JARs together are only 20kB.

See you at Java EE Workshops at Munich Airport, Terminal 2 or Virtual Dedicated Workshops / consulting

Summer Workshops: From Java EE 7 Bootstrap and Effective Java EE 7 to Java EE 7 Architectures


A book about rethinking Java EE Patterns
...the last 150 posts
...the last 10 comments