KCS methodology


I’ve been working with the Knowledge Centered Services (writing solutions and articles) since 2018 so 3y+ now. I think it is one of those ideas it worth sharing. It is considerable easily to write solutions and some principles and practices. From solve solve loop: capture, structure, reuse, improve. To the evolve loop: content health, process integration, performance assessment and leadership and communication.

And it is very complementary to ITIL . Since 2014 I have experience with ITIL v3 course, but only later, 2018 is that I learned about KCS methodology. As much as knowledge is part of the workflow, not necessarily treated as the main part of it. I really don’t know how was IT/IT services/IT support without both of those methodologies.

The fact is I always had more fun to easily pass the construction of a natural procedure, which will happily be replicated, instead of a imposition in the workflow. The created solution/article will benefit not only the creator but other valid analysts and customers. That’s an easy sell.

Some principles though, are very important and can be applied every where, like defining/understanding the problem before solving – this one can be applied in almost anything in life/work. But another one I learned, is that more you write, the more you will like it. I think that’s was a big change on this blog on the last couple of years. The more I would write solutions (and I wrote more than 400 of them), the more this blog got organized and simple to read.

Interestingly, on the official website, KCS v6 Practice Guide – Technique 4.1: Reuse is Review, 80% of the problems are solved by 20% of the solution, I will disagree with that. Most of the solutions I have seen I re-used/edit somehow. Even if it was just once, the problem sometimes will help clarify another one in the future. I’d say only 20% or less of the solutions would be seldom to rarely used, but the site might imply a sense of useless, which is not the case.

Finally, I would suggest getting certification for KCS from them, it is very interesting and pushes you to learn more, at least the KCS Fundamental certification.

Elastic Metaspace


For the java followers, which have been seeing the java language evolve the last couple of years remember the big difference between JDK 7 vs JDK 8 when the metaspace was “created” as in perm gen was removed from heap. And this change made much sense, in the sense that loading information from the classes are set to be outside of the heap. Basically we have on JDK 8+ class metadata are allocated when classes are loaded in native.

However, the main impact we have seen in some scenarios, was when applications with high number class loading occupy a considerable (as in non trivial) amount of space on the memory, but now on the native side. And it was like that for quite awhile, the technical reason is that you have each class loader taking a part of the metachunks and occupying a space on its arena – the more class loaders, the more space it takes – i.e. per-class loader areas. This space would only grow with time, the more class loaders and classes are loaded.

That’s not the case anymore, and now with Elastic Metaspace, which basically introduces mechanisms of uncommitting the memory back to the OS – and commit memory only on demand (seriously, before it was just a big commited space without usage), i.e. allocator will attempt to return memory to the OS after class unloading, in a much more eagerly than it did before Elastic Metaspace, which is implemented via the Buddy Memory allocation algorithm.

And of course, more JVM options in Java means usually mean new flags, and that’s why the new JVM flag MetaspaceReclaimStrategy was introduced the flag has three options: none, balanced, and aggressive, as described on JDK-8242841. Balanced is the default.

Balancedshall enable a reasonable compromise between reclaiming memory and the incurred costs. The majority of applications should see improved memory usage after class unloading while not noticing added costs. In particular, the number of virtual memory areas should only marginally increase. This setting aims to deliver backward compatible behavior while still giving the benefit of reduced memory usage.
Aggressiveshall enable more aggressive memory reclamation at possibly increased cost. Choosing this setting means the user would be willing to increase the OS specific limit on virtual memory areas if needed. However, “aggressive” should still be a perfectly viable setting.
nonedisable memory reclamation


The consequence of the previous implementation – reserve/commit a big chunk even when not used – is that you can use more than needed and reclaiming is not an option, aka non Elastic Metaspace. If you would would like to make it this way, just set MetaspaceReclaimStrategy=none.

The new implementation, i.e. Elastic Metaspace, the tradeoff will be:

1. Losing cpu cycles in the uncommitting process ~ meaning CPU overhead.

2. uncomitting memory may increase the number of virtual memory areas (memory mappings) ~ meaning (virtual) memory overhead. Use `ulimit -v` to see the current limit. From what I searched the virtual limit would be 2^48 for 64 bits ~ still learning about it though.

Complete description of the algorithm here and overview on the JEP 387

JDK 17


Red Hat will launch OpenJDK 17 production ready at the end of this year. And there are several features which include the following:

  1. Switch expressions
  2. Text blocks
  3. Pattern matching of instanceof
  4. Records
  5. Restricting float pointing operating
  6. Hidden classes
  7. Foreign function & Memory API
  8. ZGC Prod ready ~ https://openjdk.java.net/jeps/377

I’ll be doing some blog posts about the features above.

Also, in terms of overhead, the heap/native size overhead will get smaller because of the Elastic Metaspace, instead of a static. That is very interesting and certainly, I will do some benchmarks to see the comparison.

There was much stuff removal/deprecated as well, like CMS, Nashorn, RMI activation.

It is important to highlight here that ZGC, the ultra fast GC from Oracle – similar to Shenandoah in terms of speed – is now production ready as well, I think I already did one or two blog posts about it. Shenandoah is production ready in JDK 8 and JDK 11, since it was back-ported to JDK 8.



Previously I have done some posts about Shenandoah, and now it is time to talk about Oracle’s ZGC.

ZGC has an algorithm similar to Shenandoah (in terms of concurrence GC) only it uses coloured pointers to mark the objects, and that demands 64bits, so it doesn’t have 32bits of ZGC, necessary for the reference colouring. In comparison to Shenandoah’s additional one level of abstraction (forwarding pointer) that adds one words (+the other two already in OpenJDK). The tradeoff used to be the footprint, because for each object you add one more word (warning: this is true for Shenandoah1, in Shenandoah2, it uses the mark word for the forwarding pointer, so then there is no more footprint). Of course, Shenandoah it aims for very small pauses, i.e. sub-millisecond, handle of high heap and scalable pauses. It is available for JDK 11 on Windows, Linux 64, macOS and Linux/Aarch architectures.

This is a big thing is the tradeoff Oracle’s ZGC took his 64 bit implementation, so no 32bits. I don’t think ZGC has a degradation mode (or pacing mechanism) as Shenandoah does have, meaning it will not stall the threads of the application to make the GC finish the job (it will add latency as consequence, although invisible – 42:00).

Like G1GC, and much of contrary to CMS, it does not have that many flags to set as well. As Shenandoah you can play/tune it a bit, with basic initial heap size, number of concurrent GC threads, NUMA – JDK 17 feature – Huge and large pages. On some versions one can set AlwaysPreTouch.

Arquillian testing


Arquillian testing framework helps considerably doing a simple Wildfly/EAP test.

Reasons to be very easy:
1. It is pretty simple to write a test, as any unit test should be and it allows to package the application in one function pretty smothly:

    public static WebArchive createDeployment()
        System.out.println("create Deployment");

        WebArchive archive = ShrinkWrap.create(WebArchive.class, "sample.war")
                .addAsWebInfResource(EmptyAsset.INSTANCE, "beans.xml")
                .addAsResource("validation.xml", "META-INF/validation.xml");


        archive.as(ZipExporter.class).exportTo(new File("/tmp/" + archive.getName()), true);

        return archive;

2. Using arquilllian.xml enables to select a certain specific container to be deployed, as little as the lines below to select the container:

  <container qualifier="arquillian-wildfly-managed">
      <property name="chameleonTarget">${chameleon.target}</property>
      <property name="serverConfig">standalone-full.xml</property>

3. Testing is pretty straightforward

    public void Test1() throws Exception
        System.out.println("Calling URI: " + serviceUri.toString()); //to show the url being called

        final String targetUrl = serviceUri.toString() + "hello";
        log.info("The target URL is: {}", targetUrl);
        ResteasyClient client = new ResteasyClientBuilder().build();
        ResteasyWebTarget target = client.target(targetUrl);
        ValidatedJaxRsInterface validatedJaxRs = target.proxy(ValidateJaxRsInt.class);
            log.info("Validated call responded with: {}", validation.Hello());
        catch (Exception exception)
            log.error("Got an error when calling the validated endpoint: {}", exception.getMessage(),exception);
            if (exception instanceof BadRequestException)
                BadRequestException exp = (BadRequestException) exception;
                log.error("The response was bad request :/ {}", exp.getMessage());
        log.info("Calling validation.Hello");

4. One can use chameleon or wildfly arquillian straight on the pom to get the container, like below:

        <chameleon.target>jboss eap:${jboss.version}:${container.type}</chameleon.target>

Depending on the EAP version one should use the wildfly arquillian container image instead, see difference below:

<!-- Arquillian Chameleon -->

<!--- wildfly-arquillian-container-managed -->

5. Adding validation becomes almost trivial with the validation.xml file:

   <executable-validation enabled="true">

taglib in jsp


On JSP, yes JSP, the taglib directive declares that your JSP page uses a set of custom tags, the usage of JSTL can be quick straightforward:

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>  

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Hello from JSP</title>
${label} <br>

<c:out value="Example taglib" /> <!-- the c is the tag lib using the core jstl core taglib -->
	<c:out value="Let's output this" />
	<c:set var="dummyName" scope="session" value="2000"/>
	<c:out value = "${dummyName}" />
	<c:if test="${dummyName!=null}">
		No estoy embarasada!
	<a href = "<c:url value = "https://www.youtube.com/watch?v=68-2C9L5dJM"/>">URL test</a>
	<c:forEach var="headerValue" items="${header}">
		${headerValue.key},${headerValue.value}<BR />


For a complete tutorial, my favourite references are TutorialsPoint and W3 Processing, for sure. Seeing what is useful for you project. It is interesting that one Eclipse/Netbeans just click Dynamic Web Project striaght way, no need for web.xml file as before.

JSP is appropriate for fast prototyping and easily deployment. Of course this technology is being deprecated for Django/Python, which I already had made some posts here, but will do more eventually.

StringBuilder, StringBuffer and JVM flags for Strings


When dealing with Strings, which are of course immutable objects in Java, it may be easier to use a StringBuilder or StringBuffer implementation – as suggested by Geekforgeeks

StringBuffer vs StringBuilder

StringBuffer has a slight better performance than StringBuilder and is able to deal with multiple thread accessing. But is good to know it is there.

 StringBuilder stringBuilderExample = new StringBuilder("Example");
 stringBuilderExample.append("of String Builder");

 StringBuffer stringBuffer = new StringBuffer("Example");
 stringBuffer.append(" of String Buffer");

But factually, comparing both of them in a small benchmark, the performance is the same pretty much, but for a small benchmark, stringBuffer uses a little bit less memory.

real	0m0.048s <----------------------------- 0.048s (from 0.035s up to 0.055s)
user	0m0.044s
sys	0m0.009s

String JVM flags

There are some JVM flags that come in hand when dealing with strings as well:

JVM flagResult

Special thanks

Special thanks to Francesco Marchioni and his amazing blog, the very famous mastertheboss blog. I’m his fan and pretty much have his whole collection of books on my table, DataGrid, Quarkus, EAP, JBoss.

Quick start mbean


Client Mbean

Using a JMX client one can connect to a container Server MBeans and get information very easily. On this blog I have wrote about Jconsole and JvisualVM.

My colleague, Alexander Barbosa, wrote this nice Tutorial to get info on Heap using Mbean. Basically the information comes from the `java.lang:type=Memory`. To get heap or non-heap memory.

	ObjectName memoryMXBean = new ObjectName("java.lang:type=Memory");

You may need to add the credentials for connection and using a map this can be done quick straightforward:

		credentials[0] = "admin";
		credentials[1] = "admin";
		map.put(JMXConnector.CREDENTIALS, credentials);

		// passing server credentials
        JMXConnector jmxConnector = JMXConnectorFactory.connect(serviceURL, map);

Silly mistakes to avoid:

Congratulations you forgot the `.java` part – there is nothing my sully than that:

$ javac -classpath .:$$JBOSS_HOME/bin/client/jboss-client.jar jmxTesterror: 
Class names, 'jmxTest', are only accepted if annotation processing is explicitly requested
1 error