JVM articles

Divide and conquer with fork/join framework

When performance matters (when it does not?), dealing with a big task can prove to be very costly. One of solutions for this kind of bottlenecks could be the using of divide and conquer algorithms. In Java it can be retrieved in fork/join framework.

Continue Reading β†’

CopyOnWriteArrayList as thread-safe ArrayList

Working with collections in multi-threading environment is a little bit tricky. But fortunately, Java offers some objects able to store data in thread-safe way. One of them is CopyOnWriteArrayList, introduced with Java 5.

Continue Reading β†’

CountedCompleter

Java 8 brings another type of ForkJoinTask, CountedCompleter. And because sometimes this class is considered little bit obscure, we'll try to understand it through this article.

Continue Reading β†’

Prefer collections over arrays

Arrays and collections look similar. Both handle a group of similar type of objects. However, they have some differences, going from the simplest maintainability cases going to performance ones.

Continue Reading β†’

Objects in Java 7

Java 7 was released in 2011 and brought to us, programmers, several interesting features as diamond operators or new I/O library. Yet another useful thing is less popular than two cited previously - Objects tool class.

Continue Reading β†’

EnumSet to manage permissions

Enumerations storage in Java can be achieved through classical collections, such as lists or queues. However, one specific class is adapted to manage only enums - EnumSet.

Continue Reading β†’

JPA event-driven development with entity listeners

Nowadays more and more applications are composed by several different data layers, beginning from the classical RDBMS and finishing in more adapted to some situations (search or graph relationships for example) NoSQL solutions. An interesting feature of JPA allows to notify no-JPA layer about some changes made on entities, exactly as in other solutions coming from event-driven development approach.

Continue Reading β†’

Mapped superclass in JPA

Until now in our examples we were using object inheritance based on entity classes (@Entity). However, we can also construct classes hierarchy without that, by using another JPA's annotation: @MappedSuperclass.

Continue Reading β†’

Relationship cascading in JPA

One of reasons-to-be of relational databases are relations. JPA provides very flexible way of manipulating them, through cascade attribute of annotations responsible for related objects (database tables).

Continue Reading β†’

Collections in JPA

JPA 2.0 brought some improvements for handling object collections. Before this release, to associate two objects, we were forced to define them as entities and use one from (One|Many)To(One|Many) mapping annotations. With 2.0 version came another possibility - @ElementCollection.

Continue Reading β†’

Result transformers

One of very popular pitfalls of database object mappers is the number of executed queries before constructing final entity. In Hibernate with FetchMode enum we can control better the quantity of queries executed against the database. However, in some cases we can need some supplementary help in the form of result transformers.

Continue Reading β†’

Eager and lazy collections loading

Relation database management systems (RDBMS) are based on relational model. Naturally, all mapping systems must be able to represent these relationships on application layer. JPA defines several ways to do that, but all have some common points. One of them is the technique of fetching associated data.

Continue Reading β†’

Metaspace in Java 8

One of big changes in Java 8 regarding to Java 7 was the replacement of permanent generation by metaspace. Even if this change dates from more than year ago, it's worth to dedicate some lines about this new element in memory.

Continue Reading β†’

Static and instance methods in Java

Static methods in programming have some important roles. Mostly used as utility methods, they help to differentiate normal, business objects, from universal purely non contextual ones. They also gained a lot of recognition thanks to popular libraries, such as Google Guava. But there are another role useful in the case of static methods in Java ?

Continue Reading β†’

Phaser in Java concurrency

JDK 7 introduced a interesting concurrency concept of mix between CountDownLatch and CyclicBarrier mechanisms. It's name - Phaser.

Continue Reading β†’

Java class loaders for archive files

In the previous article we saw how to load simple classes in Java. But loading classes one by one, and even exporting class files at the same way, is less practice that working with archives as JARs.

Continue Reading β†’

Reading verbosegc output

When you meet OutOfMemory or another error caused by the memory, you have some ways to debug. If you were persevering, you can use memory dump made with -XX:+HeapDumpOnOutOfMemoryError parameter. If you're even more persevering, you could see how Garbage Collector works thanks to two another JVM arguments: verbose and GC details printing.

Continue Reading β†’

Java class loaders

Often when somebody starts to learn Java, he meets the problems associated with classes loading. These problems are mostly always caused by class loaders described more in details in this article.

Continue Reading β†’

Thread pools in Java concurrency

Before writing production code based on Java's executors, we should learn another inseparable concept of concurrency, thread pools.

Continue Reading β†’

Java and mysterious byte

As a developer who learned Java basically on web applications, understanding of byte existence in Java may be difficult. In this article we'll try to explain the reason of being of byte in Java environment.

Continue Reading β†’