{"id":1068,"date":"2019-01-23T12:15:40","date_gmt":"2019-01-23T12:15:40","guid":{"rendered":"http:\/\/smartfoxserver.com\/blog\/?p=1068"},"modified":"2019-01-23T12:18:10","modified_gmt":"2019-01-23T12:18:10","slug":"java-9-to-11-and-smartfoxserver-2x","status":"publish","type":"post","link":"https:\/\/smartfoxserver.com\/blog\/java-9-to-11-and-smartfoxserver-2x\/","title":{"rendered":"Java 9 to 11 and SmartFoxServer 2X"},"content":{"rendered":"<p>In this article we&#8217;re going to take a quick tour of the fundamental changes that Java releases 9 through 11 have introduced, their implications for development, deployment and how SmartFoxServer 2X will move forward in relation to the new and faster cycles of Java releases.<\/p>\n<p><!--more--><\/p>\n<h2>\u00bb Java 9, where it all started<\/h2>\n<p>After\u00a0three years since the launch of Java 8 the long awaited\u00a0<strong>JDK 9\u00a0<\/strong>was finally released bringing several\u00a0significant\u00a0revolutions to the platform such as:<\/p>\n<ul>\n<li>Modularity<\/li>\n<li>Faster release cycles<\/li>\n<li>Multiple distributions and support plans<\/li>\n<\/ul>\n<p>While the list of Java 9 new features was quite extensive the three items above\u00a0have\u00a0special implications on almost all aspects of an application life cycle, from coding to deployment\u00a0to maintenance.<\/p>\n<h3>Modularity<\/h3>\n<p><img loading=\"lazy\" class=\"noShadow alignright\" src=\"http:\/\/smartfoxserver.com\/blog\/wp-content\/uploads\/2019\/01\/lego-bricks.jpg\" alt=\"\" width=\"180\" height=\"120\" \/>The Java runtime has notably been monolithic since its inception back in 1996, in fact we can find\u00a0most of the\u00a04500+\u00a0classes that comprise the JDK inside the infamous <strong>rt,jar<\/strong>\u00a0file located under jre\/bin\/lib\/, which these days is over 60MB in size.<\/p>\n<p>This in turn\u00a0can make it cumbersome to provide a slim runtime for Java-based applications, especially for embedded devices where\u00a0the app code can be\u00a0smaller than the runtime itself.<\/p>\n<p>Java 9 addresses this issue by\u00a0providing a new module system, <strong>JPMS<\/strong>\u00a0(Java Platform Module System), that allows the\u00a0JRE\u00a0to be\u00a0very slim and\u00a0offers\u00a0tools for deploying\u00a0custom runtimes with only the necessary modules.<\/p>\n<p>More specifically the core classes of the\u00a0J2SE has been split into 27 modules (under different categories)\u00a0that developers can select and include in their application&#8217;s runtime and leave the rest out, to minimize overhead.<\/p>\n<p>JPMS however is not just about organizing large libraries of code but it also\u00a0offers new levels of encapsulation to completely hide packages that are not meant to be exposed to the outside\u00a0world. This\u00a0can have crucial implications when moving from a previous Java runtime to version 9 or higher.<\/p>\n<p>A practical example\u00a0of this\u00a0is the use of\u00a0<strong>reflection<\/strong>\u00a0which\u00a0is no longer allowed to\u00a0hack inside any\u00a0class from any package and bypass field accessibility. Because of\u00a0it there have been heated debates on how modularity should work especially in relation to\u00a0popular\u00a0libraries\u00a0such as JPA, Hibernate, Spring and similar tools that\u00a0rely heavily on reflective access.<\/p>\n<p>To avoid a backward compatibility earthquake, JDK 9 comes with an <strong>encapsulation kill switch<\/strong>, in other words it is possible to turn off all the access limitations imposed by JPMS, for the time being, and keep working as in &#8220;old Java&#8221;. However this is only temporary and eventually the kill switch will be removed and applications will need to be restructured (or rewritten) to use JPMS as intended.<\/p>\n<h3>Faster Release Cycles<img loading=\"lazy\" class=\"noShadow alignright\" src=\"http:\/\/smartfoxserver.com\/blog\/wp-content\/uploads\/2019\/01\/dev-cycles.jpg\" alt=\"\" width=\"150\" height=\"145\" \/><\/h3>\n<p>Since the release of Java 9, Oracle has announced their intention to\u00a0launch <strong>two new major JDK\u00a0releases every year<\/strong>, typically 6 months apart (March and September).<\/p>\n<p>With the faster release pacing also comes a different support model where only certain versions of the JDK will receive <strong>long term support<\/strong> (LTS), while others will not. LTS is a three year plan where Oracle will continue to provide patches for security issues, bug fixes etc. However, for JDKs not marked as LTS there won&#8217;t be this kind of support and the only way to get an update would be to migrate to the next major release coming six months later.<\/p>\n<p>For\u00a0instance JDK 8 is considered LTS and as such is going to be supported until 2020, while Java 9 and 10 are not. The latest JDK 11 is an LTS release and it will continue to be supported for the next three years.<\/p>\n<p>There are also other considerations in the Oracle license that make distinctions between commercial and non commercial use that\u00a0can impact the duration of the LTS terms. We&#8217;re not going to go into the details of this here, but we&#8217;ll provide links for you to learn more, if you&#8217;re interested.<\/p>\n<h3>Multiple distributions and support plans<img loading=\"lazy\" class=\"noShadow alignright\" src=\"http:\/\/smartfoxserver.com\/blog\/wp-content\/uploads\/2019\/01\/open-jdk-logo.jpg\" alt=\"\" width=\"150\" height=\"182\" \/><\/h3>\n<p>The multi-distribution feature is not exactly a novelty that came with\u00a0Java 9 but it&#8217;s\u00a0now more relevant\u00a0because different JDK binary releases come with different licenses of use.<\/p>\n<ul>\n<li><strong>Oracle JDK<\/strong>: is the official Java platform provided by Oracle with\u00a0long term support only for selected releases and a few more restrictions for commercial uses.<\/li>\n<li><strong>Open JDK<\/strong>: is the GPL2 based Java that has no restrictions compared\u00a0to Oracle&#8217;s but also does not provide LTS and therefore every release has only a 6 month window of support.<\/li>\n<li><strong>Other implementations:\u00a0<\/strong>there are third party implementations of the JDK provided by companies such as RedHat, Azul, Amazon and\u00a0others. Each have their pros and cons and come with their own support plans. We&#8217;ll\u00a0touch\u00a0on <strong>Amazon&#8217;s own JDK<\/strong> later in this article as it is of particular interest for SmartFoxServer.<\/li>\n<\/ul>\n<h2>\u00bb\u00a0How is SFS2X going to handle the Java revolution?<img loading=\"lazy\" class=\"noShadow alignright\" src=\"http:\/\/smartfoxserver.com\/blog\/wp-content\/uploads\/2019\/01\/client-sfs-logo.jpg\" alt=\"\" width=\"150\" height=\"66\" \/><\/h2>\n<p>For the past 2 years, since SFS2X 2.12, we have been embedding Java 8 as the default runtime and\u00a0we don&#8217;t expect this to change\u00a0for several more years.<\/p>\n<p>While Java 9 through 11 offer interesting new features and changes, none of them are crucial\u00a0for the development of the next features planned for SmartFoxServer 2X, therefore we don&#8217;t\u00a0expect\u00a0to switch to\u00a0JDKs higher than 8 in the incoming future.<\/p>\n<p>However, since our customers might be curious or in need to use specific features of\u00a0 Java 9\/10\/11 we\u00a0can guarantee that\u00a0SFS2X\u00a0will run flawlessly in\u00a0all of the most recent JDKs. This way developers can simply download the server, replace the embedded JRE and they are good to go.<\/p>\n<p>This comes with an important caveat: SmartFoxServer 2X\u00a0will work smoothly with any JDK from 9 to 11 (and possibly beyond) provided that the <strong>encapsulation kill switch is kept turned on<\/strong> (which is the default mode). Since SFS2X uses reflection and depends on libraries that\u00a0also use reflective access, it&#8217;s not compatible with JPMS encapsulation strict rules.<\/p>\n<h3>\u00bb\u00a0F.A.Q.<\/h3>\n<p><strong>What will happen when the kill switch is removed in a future JDK release?<\/strong><\/p>\n<p>Once Java finally removes the encapsulation kill switch SmartFoxServer 2X will cease to work and thus will become incompatible with specific releases of the JDK. The solution to this problem would be to rewrite substantial parts of the core services and replace\u00a0different libraries that offer critical functionalities.<\/p>\n<p>While this is in the realm of possibilities, the effort could easily match that of rewriting the product from scratch. Keep reading for more info on this.<\/p>\n<p><strong>Java 8 support expires soon, by January 2020. Are you not going to switch to the next LTS release of Java (a.k.a. Java 11)?<br \/>\n<\/strong><\/p>\n<p>Not necessarily. While Oracle&#8217;s JDK 8 is going to be supported only for one more year (at the time of writing) <a href=\"https:\/\/aws.amazon.com\/corretto\/\" target=\"_blank\" rel=\"noopener noreferrer\">Amazon&#8217;s JDK<\/a> (codename &#8220;<strong>Corretto<\/strong>&#8220;) will continue to provide support until at least <a href=\"https:\/\/aws.amazon.com\/blogs\/opensource\/amazon-corretto-no-cost-distribution-openjdk-long-term-support\/\">July 2023<\/a>. So our plan is to stick with this release of the JRE for the time being.<\/p>\n<p><strong>Is Amazon&#8217;s JDK production ready?<\/strong><\/p>\n<p>Yes, it is. <strong>Corretto<\/strong> is built on the Java platform specifications and is meant as a drop-in replacement for\u00a0another Java distribution, such as Oracle&#8217;s or OpenJDK. We&#8217;ve tested the runtime running SmartFoxServer 2X under different stress scenarios and have found it to be\u00a0perfectly stable and on par with the performance of the Oracle\/OpenJDK runtimes.<\/p>\n<h2>\u00bb Conclusions and a\u00a0word to the wise<\/h2>\n<p>The recent\u00a0updates\u00a0to the Java platform provide a needed\u00a0renovation\u00a0of the environment, with significant improvements to the language, tools and runtime. This sets the stage for a more modern Java for the next decade, and the new fast release cycles is quickly catching up\u00a0with\u00a0 other big contenders such as C# and Swift.<\/p>\n<p>However before jumping on the\u00a0 latest Java 11 bandwagon we&#8217;d like to caution that the transition\u00a0from any JDK\u00a0&lt;= 8 is not necessarily\u00a0pain free. A lot of changes have been introduced in the standard API and JVM, which may impact your workflow, debugging, management and so forth.<\/p>\n<p>Before deciding to switch we suggest to take some time and investigate what has changed and what libraries and tools you\u00a0use may need to be upgraded or replaced.<\/p>\n<p>As we have mentioned, SmartFoxServer 2X runs perfectly fine in Java 9\/10\/11 but your code may not and it should be tested as well, including the relative dependencies and any other tool that is part of your workflow (profilers, code obfuscators, build tools etc&#8230;)<\/p>\n<p>Finally here are some\u00a0in-depth\u00a0resources we recommend you\u00a0to consult\u00a0in order to learn more:<\/p>\n<ul>\n<li><a href=\"https:\/\/www.youtube.com\/watch?v=mFyzyVnYcoY\" target=\"_blank\" rel=\"noopener noreferrer\">JDK 9, 10, 11 and Beyond: Delivering New Feature in the JDK<\/a> (YouTube presentation)<\/li>\n<li><a href=\"https:\/\/codete.com\/blog\/java-8-java-11-quick-guide\/\" target=\"_blank\" rel=\"noopener noreferrer\">From Java 8 to Java 11 \u2013 Quick Guide<\/a><\/li>\n<li><a href=\"https:\/\/jaxenter.com\/jdk-9-pitfalls-136968.html\" target=\"_blank\" rel=\"noopener noreferrer\">JDK 9: Pitfalls for the unwary<\/a><\/li>\n<li><a href=\"http:\/\/blog.codefx.org\/java\/reflection-vs-encapsulation\/\" target=\"_blank\" rel=\"noopener noreferrer\">Reflection vs Encapsulation<\/a><\/li>\n<li><a href=\"https:\/\/dzone.com\/articles\/amazon-corretto-another-jdk\" target=\"_blank\" rel=\"noopener noreferrer\">Amazon Corretto: Another OpenJDK<\/a><\/li>\n<\/ul>\n<p>If you have any questions or would like to discuss this topic further you can\u00a0get in touch with\u00a0us on our <a href=\"https:\/\/www.smartfoxserver.com\/forums\/index.php\" target=\"_blank\" rel=\"noopener noreferrer\">support forums<\/a>.<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In this article we&#8217;re going to take a quick tour of the fundamental changes that Java releases 9 through 11 have introduced, their implications for development, deployment and how SmartFoxServer 2X will move forward in relation to the new and faster cycles of Java releases.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[23],"tags":[104,103,105,102,7],"_links":{"self":[{"href":"https:\/\/smartfoxserver.com\/blog\/wp-json\/wp\/v2\/posts\/1068"}],"collection":[{"href":"https:\/\/smartfoxserver.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/smartfoxserver.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/smartfoxserver.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/smartfoxserver.com\/blog\/wp-json\/wp\/v2\/comments?post=1068"}],"version-history":[{"count":20,"href":"https:\/\/smartfoxserver.com\/blog\/wp-json\/wp\/v2\/posts\/1068\/revisions"}],"predecessor-version":[{"id":1105,"href":"https:\/\/smartfoxserver.com\/blog\/wp-json\/wp\/v2\/posts\/1068\/revisions\/1105"}],"wp:attachment":[{"href":"https:\/\/smartfoxserver.com\/blog\/wp-json\/wp\/v2\/media?parent=1068"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/smartfoxserver.com\/blog\/wp-json\/wp\/v2\/categories?post=1068"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/smartfoxserver.com\/blog\/wp-json\/wp\/v2\/tags?post=1068"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}