Adam Bien's Weblog

Injectable, Configurable, Resilient and Monitorable ThreadPools in Java EE 7 -- Porcupine Is Available

The Apache 2.0 licensed Project Porcupine is based on JSR 236: Concurrency Utilities for Java EE and allows you to setup injectable thread pools on-the-fly.

Each thread pool is created according to sensible conventions and produces an injectable statistics POJO. Not only the configuration, but also all major components are extensible without any additional configuration:


import com.airhacks.porcupine.execution.boundary.Dedicated;
import java.util.concurrent.ExecutorService;
import javax.inject.Inject;

public class MessagesService {

    @Inject
    @Dedicated
    ExecutorService light;

    @Inject
    @Dedicated
    ExecutorService heavy;
    //...
}

The installation is easy:


<dependency>
	<groupId>com.airhacks</groupId>
	<artifactId>porcupine</artifactId>
	<version>NEWEST_VERSION</version>
	<scope>compile</scope>
</dependency>
and the dependency small (16 kB).

Enjoy https://github.com/AdamBien/porcupine and see you at workshops.adam-bien.com. Porcupine is heavily discussed during the workshops. Stay in touch with airhacksnews.com!.


NEW workshop: Build a Java EE 7 / Java 8 Application from Scratch, May 11th, 2015, Airport Munich

Newsletter: airhacksnews.com

A book about rethinking Java EE Patterns

Listing Docker Containers with Nashorn

Nashorn is a convenient REST-service client:


#!/usr/bin/jjs -fv
var host = "DOCKER_HOST"
var dockerUri="http://${host}:5555/containers/json";
var command = "curl ${dockerUri}";
$EXEC(command);
var containers = JSON.parse($OUT);
for each(container in containers){
	print("${container.Image} 	 ${container.Names[0]}	 ${container.Status}");
}

See also: https://github.com/AdamBien/watchdock

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


NEW workshop: Build a Java EE 7 / Java 8 Application from Scratch, May 11th, 2015, Airport Munich

Newsletter: airhacksnews.com

A book about rethinking Java EE Patterns

Java is #2 at the Tiobe Community Index

According to the TIOBE Community Index Java is #2, C is #1 and JavaScript is #7 and the programming language of 2014.

So if you learned C at school and are using JavaEE at the backend, HTML 5 + JavaScript at the frontend you are one of the cool kids :-)

Subscribe to airhacksnews.com newsletter.


NEW workshop: Build a Java EE 7 / Java 8 Application from Scratch, May 11th, 2015, Airport Munich

Newsletter: airhacksnews.com

A book about rethinking Java EE Patterns

JSON-P and JAX-RS 2 Client Maven Dependencies For RESTEasy

RESTEasy is a JAX-RS 2.0 implementation and comes with JAX-RS 2.0 client implementation / provider.

To use RESTEasy as a JAX-RS 2.0 client implementation (e.g. for system testing) you will have to declare the following dependencies in pom.xml:


<dependency>
    <groupId>org.jboss.resteasy</groupId>
    <artifactId>resteasy-client</artifactId>
    <version>3.0.10.Final</version>
</dependency>
<dependency>
	<groupId>org.jboss.resteasy</groupId>
    <artifactId>resteasy-json-p-provider</artifactId>
    <version>3.0.10.Final</version>
</dependency>

The choice of the JAX-RS implementation does not have any effect at the code--it remains implementation independent:

import javax.ws.rs.client.Client;
import javax.ws.rs.client.ClientBuilder;

@Test
public void oracle() {
	Client client = ClientBuilder.newClient();
	String content = client.target("http://www.oracle.com/technetwork/java/index.html").
			request().
			get(String.class);
	assertNotNull(content);
	assertTrue(content.contains("java"));
}

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


NEW workshop: Build a Java EE 7 / Java 8 Application from Scratch, May 11th, 2015, Airport Munich

Newsletter: airhacksnews.com

A book about rethinking Java EE Patterns

Transactions, Scopes, Single Page Apps, Killer Servers, Complex JSON, Modularization Again--Questions For the 10th Airhacks Questions and Answers

Questions for the first 2015 airhacks.tv, but late show at Januar, 12th, 6 PM CET:

  1. Year 2014 Review and Announcements
  2. Introducing project headlands
  3. What are your overall “Java EE” favorites? (peter, via email)
  4. Which technology stack would you prefer to choose for an interactive single page mobile app? As JavaFX is not supported by Apple, I am currently experimenting with a hybrid web app technology stack: GWT, MGWT, PhoneGap. I evaluated Vaadin for this purpose, but integrating custom widgets into their complex architecture seems to be a real pain. Something like Java EE + Primefaces seems not be the first candidate for a single page app to me. What would your approach be? (Jens)
  5. What application server are you currently using for your new Java EE7 projects? Would you recommend GlassFish 4.1 despite the lack of commercial support, or is better to go with WildFly 8.2.0? Antonio
  6. What is your opinion about Project Avatar (https://avatar.java.net/)? WurstFromHell
  7. Portable error reporting with JAX-RS 2.0 Benjamin
  8. How to map complex object strategies to JSON? Remko
  9. I would like to know what would be the best approach for modular JSF applications.

    Most of the existing examples consist in creating a jar, for web applications, where the resources are located in the META-INF folder, having unique named properties files, and using CDI to announce the module existences henry
  10. What about building enterprise systems made of multiple ears, whereas each ear is build as you described? Still, there are many issues not covered yet by appserver providers and JEE.

    (1) One example is that remote ejb proxies are not automatically recovered after deployment - custom proxy factories need to be implemented.

    (3) Another one is the communication between wars … there is actually no kind web client project type available to provide an API for JSF apps - needed to integrate apps at different WARs (for EJB jars we JEE provides client projects…).

    (3) Another aspect … how to develop single EARs with one or more teams/team members? How to hide parts of sources to subcontractors, but ensure deployability?

    From my perspective, development of integrated service landscapes with JEE is still a challenging and not that easy as many hello world example show … that’s why - hope to see more of really real-world enterprise patterns here and also provided by next JEE versions! Andreas Freier
  11. I would like to have something like:

    @Inject @Any private Instance providers;

    Where ‘ServiceRemote’ is a @Remote interface, and there are multiple implementations deployed in different EARs.Chris
  12. I was looking at the Arunja implementation of TransactionSynchronizationRegistry in JBoss and get/putResource works by accessing the resource from the transaction object. You state that this mechanism is independent of TLS, but how does the container get the TSR in the first place, so that it can inject it, if it doesn’t do it using TLS? Ant
  13. Today I saw some code were a @SessionScoped bean was injected into a @Stateless

    EJB.Up-to-now my understanding was that such a constellation will lead to
    unpredictable behavior, since the stateless EJB is not stateless anymore.After googling that topic I figured out that may people stating, such a
    constellation is absolutely valid.I can’t believe that’s true. How is this working?

    Do you have an advice for me? Juergen
  14. Can you please explain how to configure hazelcast as a distributed cache on multiple servers? Eyal

Do you have any additional questions? Ask now, or wait a month :-)

You can ask additional questions live, during the show using the chat: http://www.ustream.tv/channel/adambien, twitter (hashtag "#airhacks") or (the best option): using channel ##airhacks on http://freenode.net.

See also other screencasts at: http://tv.adam-bien.com or subscribe to http://www.youtube.com/user/bienadam.

See you at Java EE Workshops at Munich Airport, Terminal 2 or on demand and in a location very near you: airhacks.io!


NEW workshop: Build a Java EE 7 / Java 8 Application from Scratch, May 11th, 2015, Airport Munich

Newsletter: airhacksnews.com

A book about rethinking Java EE Patterns

JCache / JSR-107 RESTification--Project Headlands v0.0.1

Project Headlands is a Java EE 7 / Java 8 WAR which exposes the JCache API via JAX-RS (REST). See sample API scenario. Headlands was tested on WildFly and GlassFish.

Headlands uses hazelcast.org as default JCache SPI. The Reference Implementation could be used as well.

Because out-of-the-box Headlands ships with hazelast, by deploying WARs on multiple servers you get a distributed cache / in-memory grid "for free".

Headlands is already used in production. We will also discuss headlands together with docker as one of the samples at the upcoming Airhacks: Java EE Microservices.


NEW workshop: Build a Java EE 7 / Java 8 Application from Scratch, May 11th, 2015, Airport Munich

Newsletter: airhacksnews.com

A book about rethinking Java EE Patterns

"Airhacks News" Mailing List

If you like to be notified about upcoming (airhacks) events (http://workshops.adam-bien.com, http://airhacks.tv, or some of my public speaking activities), subscribe to the:

It is trivial to unsubscribe :-)

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


NEW workshop: Build a Java EE 7 / Java 8 Application from Scratch, May 11th, 2015, Airport Munich

Newsletter: airhacksnews.com

A book about rethinking Java EE Patterns

New Java 8 Date and JPA 2.1 Integration

JPA 2.1 does not directly support the java.time API. However, with an AttributeConverter implementation you can easily integrate Java 8 (or any other dates) with JPA:


import java.time.Instant;
import java.time.LocalDate;
import java.util.Date;
import javax.persistence.AttributeConverter;
import javax.persistence.Converter;

@Converter(autoApply = true)
public class LocalDateConverter implements AttributeConverter<LocalDate, Date> {

    @Override
    public Date convertToDatabaseColumn(LocalDate date) {
        Instant instant = Instant.from(date);
        return Date.from(instant);
    }

    @Override
    public LocalDate convertToEntityAttribute(Date value) {
        Instant instant = value.toInstant();
        return LocalDate.from(instant);
    }
}


The @Converter(autoApply = true) will automatically activate the converter and keep your domain classes clean:

import java.time.LocalDate;

@Entity
public class Spaceship {

    @Id
    private long id;
    private String name;
    private int speed;
    private LocalDate arrival;
}

The example above was taken from Java 8 with Java EE 7. See you at http://airhacks.com or Virtual Dedicated Workshops / consulting!


NEW workshop: Build a Java EE 7 / Java 8 Application from Scratch, May 11th, 2015, Airport Munich

Newsletter: airhacksnews.com

A book about rethinking Java EE Patterns

realworldpatterns.com
...the last 150 posts
...the last 10 comments
License