Adam Bien's Weblog

Transaction Monitoring with WildFly

The WildFly Java EE application server comes with extensive monitoring capabilities. In this screencast I'm monitoring the number of commits and rollbacks of a deployed Java EE application:

See you at: Tuning and troubleshooting Java EE 7 applications


NEW online workshop: WebStandards Igniter (online)

Airport MUC workshops: Java EE 7: Bootstrap, Effective, Architectures, Web, React and Angular, Testing and Microservices

Newsletter: airhacks.news

A book about rethinking Java EE Patterns

Java 8: Catching Integer Overflows

In Java the addition: Integer.MAX_VALUE + Integer.MAX_VALUE results in -2 without complaining. The following unit test passes:

    
        @Test
        public void addWithOverflow() {
            int result = Integer.MAX_VALUE + Integer.MAX_VALUE;
            assertThat(result, is(-2));
        }
    

Java 8 allows you to catch the overflows as ArithmeticException instances by using the Math.addExact (multiplyExact, subtractExact etc.) method.

The following test also passes:

    
        @Rule
        public ExpectedException expected = ExpectedException.none();
    
        @Test
        public void addWithOverflowAndCatch() {
            expected.expect(ArithmeticException.class);
            expected.expectMessage(containsString("integer overflow"));
            Math.addExact(Integer.MAX_VALUE, Integer.MAX_VALUE);
        }    

See you at Java EE Workshops at Munich Airport, Terminal 2 or Virtual Dedicated Workshops / consulting. Is Munich's airport too far? Learn from home: airhacks.io.


NEW online workshop: WebStandards Igniter (online)

Airport MUC workshops: Java EE 7: Bootstrap, Effective, Architectures, Web, React and Angular, Testing and Microservices

Newsletter: airhacks.news

A book about rethinking Java EE Patterns

WebStandards Igniter On-Demand Workshop

80+ episodes of continuous HTML 5, CSS 3, JavaScript (ES 6/7) coding workshop is available: webstandards.training. Only vanilla WebStandards, without any external frameworks or dependencies, were used.

Are you already building, or still migrating? Learn once, apply anywhere :-):

See you also at: WebStandards Igniter Workshop at Munich Airport, Terminal 2 or Virtual Dedicated Workshops / consulting.


NEW online workshop: WebStandards Igniter (online)

Airport MUC workshops: Java EE 7: Bootstrap, Effective, Architectures, Web, React and Angular, Testing and Microservices

Newsletter: airhacks.news

A book about rethinking Java EE Patterns

42nd airhacks.tv is available -- The Answer to all questions included

The airhacks.tv 42nd episode with "The Answer to all questions" is available:

Any questions left? Ask now or suggest a topic: https://gist.github.com/AdamBien/ec94900a3efd5d621bf4f00cc8a0dbac.

See you at Java EE Workshops at Munich Airport, Terminal 2 or Virtual Dedicated Workshops / consulting. Is Munich's airport too far? Learn from home: airhacks.io.


NEW online workshop: WebStandards Igniter (online)

Airport MUC workshops: Java EE 7: Bootstrap, Effective, Architectures, Web, React and Angular, Testing and Microservices

Newsletter: airhacks.news

A book about rethinking Java EE Patterns

Early Autumn Java (EE) / Web Events

See you soon at:


NEW online workshop: WebStandards Igniter (online)

Airport MUC workshops: Java EE 7: Bootstrap, Effective, Architectures, Web, React and Angular, Testing and Microservices

Newsletter: airhacks.news

A book about rethinking Java EE Patterns

A Java EE 7+ Alternative To EJB Timers

In addition to EJB timers (Simplest Possible EJB 3.1 Timer), with Java EE 7+ you can directly inject ManagedScheduledExecutorService, a subclass of ScheduledExecutorService available in stock Java SE:

    
        import java.time.LocalTime;
        import java.util.concurrent.TimeUnit;
        import javax.annotation.PostConstruct;
        import javax.annotation.Resource;
        import javax.ejb.Singleton;
        import javax.ejb.Startup;
        import javax.enterprise.concurrent.ManagedScheduledExecutorService;
        
        @Startup
        @Singleton
        public class Scheduler {
        
            static final long INITIAL_DELAY = 0;
            static final long PERIOD = 2;
        
            @Resource
            ManagedScheduledExecutorService scheduler;
        
            @PostConstruct
            public void init() {
                this.scheduler.scheduleAtFixedRate(this::invokePeriodically, 
                        INITIAL_DELAY, PERIOD, 
                        TimeUnit.SECONDS);
            }
        
            public void invokePeriodically() {
                System.out.println("Don't use sout in prod " + LocalTime.now());
            }
        
        }
    
Immediately after deployment, you should find the following output (likely with different timestamp :-):
    
        Info:   Don't use sout in prod 11:31:39.093
        Info:   Don't use sout in prod 11:31:41.097
        Info:   Don't use sout in prod 11:31:43.096
    
(ManagedScheduledExecutorService replaced EJB 3.1 timers in a project as a workaround to appserver configuration issues in production) See you at Java EE Workshops at Munich Airport, Terminal 2 or Virtual Dedicated Workshops / consulting. Is Munich's airport too far? Learn from home: airhacks.io.


NEW online workshop: WebStandards Igniter (online)

Airport MUC workshops: Java EE 7: Bootstrap, Effective, Architectures, Web, React and Angular, Testing and Microservices

Newsletter: airhacks.news

A book about rethinking Java EE Patterns

Microservices' Impact On App Design, Lightweight Java EE and Java EE-stic HTML 5 ...or my JavaOne 2017 sessions


Session ID: CON5252
Session Title: Microservices and Cloud-Driven Code Simplification
Room: Moscone West - Room 2003 Date: 10/03/17
Start Time: 09:30:00 AM
End Time: 10:15:00 AM

Session ID: CON5567
Session Title: The Java EE-stic (=No Dependencies) Way to Develop HTML5 Applications
Room: Moscone West - Room 2006 Date: 10/04/17
Start Time: 09:30:00 AM
End Time: 10:15:00 AM

Session ID: CON5578
Session Title: Java EE: Heavyweight or Lightweight—Mythbusters
Room: Moscone West - Room 2020 Date: 10/04/17
Start Time: 08:30:00 AM
End Time: 09:15:00 AM

I'm also invited to the panel:

Session Title: Powerful Lessons from Top Java EE Experts
Room: Moscone West - Room 2002: Java User Group Track 
Date: 10/01/17
Start Time: 04:00:00 PM
End Time: 04:45:00 PM

Thanks and see you soon at JavaOne 2017, airhacks.com or airhacks.io


NEW online workshop: WebStandards Igniter (online)

Airport MUC workshops: Java EE 7: Bootstrap, Effective, Architectures, Web, React and Angular, Testing and Microservices

Newsletter: airhacks.news

A book about rethinking Java EE Patterns

42- the answer, Fork Join, Pixel Perfect JSF, Building React and Angular, Scanning JAX-RS, Async CDI Events, Monolith or Topics For 42nd airhacks.tv

Topics for the 42nd airhacks.tv:

  1. 42 airhacks.tv - the answer to all questions
  2. ForkJoin support in Java EE 8
  3. Java FX in the browser
  4. Code coverage in system tests
  5. Opensource Java EE
  6. Auto-scanning JAX-RS resources
  7. Java and the job market
  8. @Stateless as an interceptor?
  9. Asynchronous CDI Events
  10. Empty POST or PUT
  11. @Stateful EJBs and usecases for the Gateway pattern
  12. Will CDI replace EJB in the future?
  13. Java EE 7 server recommendations
  14. GlassFish clustering / workshop
  15. JSF and pixel perfect applications
  16. Impact of react and angular on the delivery pipeline
  17. How to build JS frontends with Java EE backends
  18. Using multithreaded JAX RS 2.0 in Java SE
  19. Incrementally splitting a monolith: protocols, security processes

See full topics gist.

Ask questions during the show via twitter mentioning me: http://twitter.com/AdamBien (@AdamBien) or using the hashtag: #airhacks. You can join the Q&A session live each first Monday of month, 6 P.M at airhacks.tv or http://www.ustream.tv/channel/adambien


NEW online workshop: WebStandards Igniter (online)

Airport MUC workshops: Java EE 7: Bootstrap, Effective, Architectures, Web, React and Angular, Testing and Microservices

Newsletter: airhacks.news

A book about rethinking Java EE Patterns

Reactivity, Security, JSF Testing, AMQP, Encryption, Trends or 41st airhacks.tv is available

25+ questions ranging from Java 9 Logging, over Reactive Programming and differences to CompletableFuture, testing JSF, AMQP to using frameworks or not, were answered during the 41st airhacks.tv:

Any questions left? Ask now or wait a month.

Btw: all airhacks workshops at MUC airport are well booked. See you soon: Java EE Workshops at Munich Airport, Terminal 2 or Virtual Dedicated Workshops / consulting. Is Munich's airport too far? Learn from home: airhacks.io.


NEW online workshop: WebStandards Igniter (online)

Airport MUC workshops: Java EE 7: Bootstrap, Effective, Architectures, Web, React and Angular, Testing and Microservices

Newsletter: airhacks.news

A book about rethinking Java EE Patterns

How to establish JMX connection to JVM running in docker

For remote monitoring of JVM processes (running in a docker container) you will have to activate remote JMX monitoring with the following JVM parameters:


        -Dcom.sun.management.jmxremote 
        -Dcom.sun.management.jmxremote.port=[RMI_PORT] 
        -Dcom.sun.management.jmxremote.rmi.port=[RMI_PORT]
        -Djava.rmi.server.hostname=[EXTERNAL_IP_OF_THE_CONTAINER]    

Both RMI_PORTs could have the same value (e.g. 9090). The EXTERNAL_IP_OF_THE_CONTAINER has to be the IP address with which the JVM process is accessible. Localhost or 127.0.0.1 won't work.

The following two parameters completely disable transport encryption and access control. They increase convenience and disable security at the same time:


        -Dcom.sun.management.jmxremote.ssl=false 
        -Dcom.sun.management.jmxremote.authenticate=false 

Given the RMI_PORT=9090, you can launch the process with docker run -p 8080:8080 -p 9090:9090 --name jmx airhacks/tomee-jmx and connect with jvisualvm, jconsole, jmc with EXTERNAL_IP_OF_THE_CONTAINER:9090.

Checkout out the instrumented TomEE dockerfile: tomee-jmx from docklands

See you at Java EE Microservices. and Tuning and troubleshooting Java EE 7 Microservices Is Munich's airport too far? Learn from home: javaeemicro.services.


NEW online workshop: WebStandards Igniter (online)

Airport MUC workshops: Java EE 7: Bootstrap, Effective, Architectures, Web, React and Angular, Testing and Microservices

Newsletter: airhacks.news

A book about rethinking Java EE Patterns

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