{"id":529,"date":"2016-09-28T23:14:01","date_gmt":"2016-09-28T15:14:01","guid":{"rendered":"https:\/\/www.techcoil.com\/blog\/?p=529"},"modified":"2018-09-04T23:50:21","modified_gmt":"2018-09-04T15:50:21","slug":"how-i-make-my-java-programs-run-faster-on-my-raspberry-pi-3","status":"publish","type":"post","link":"https:\/\/www.techcoil.com\/blog\/how-i-make-my-java-programs-run-faster-on-my-raspberry-pi-3\/","title":{"rendered":"How I make my Java programs run faster on my Raspberry Pi 3"},"content":{"rendered":"<p>When my first attempt to <a href=\"https:\/\/www.techcoil.com\/blog\/setting-up-gitbucket-on-raspberry-pi-3-with-an-ubuntu-server-15-10-3-image\/\" title=\"Setting up GitBucket on Raspberry Pi 3 with an Ubuntu Server 15.10.3 image\" target=\"_blank\">install GitBucket on my Raspberry Pi 3<\/a> highlighted to me that it was the JVM that caused GitBucket to have sluggish performance, I did not invest more time to improve the performance of the JVM that I had installed on my Raspberry Pi 3. Instead, I went on to <a href=\"https:\/\/www.techcoil.com\/blog\/setting-up-go-git-service-on-a-ubuntu-server-15-10-3-image-on-my-raspberry-pi-3\/\" title=\"Setting up Go Git Service on a Ubuntu Server 15.10.3 image on my Raspberry Pi 3\" target=\"_blank\">install Go Git Service on my Raspberry Pi 3<\/a> to act as the Git server to manage the source codes of my hobby projects.<\/p>\n<p>However, I just couldn't get over my belief that Java programs would perform badly on my Raspberry Pi 3; after all Java was the first programming language that I learnt and I often use it to build software at work. Furthermore, with an Ubuntu Server 15.10.3 setup on my Raspberry Pi 3, I could use my Raspberry Pi 3 as an integration server for my Java hobby projects and be pretty sure that if my Java hobby projects run on my Raspberry Pi 3, they will most probably run on a Ubuntu Server 15.10.3 <a href=\"https:\/\/m.do.co\/c\/68b7d9b94341\" title=\"Link to DigitalOcean\" target=\"_blank\">DigitalOcean<\/a> droplet as well.<\/p>\n<p>After spending some time researching the topic, I did manage to make my Java programs run around 10 times faster on my Raspberry Pi 3. This post documents the steps that I went through to speed up my Java programs on my Raspberry Pi 3.<\/p>\n<h2>Using another Java Virtual Machine to run my Java programs<\/h2>\n<p>In my first attempt to get GitBucket running, I had installed OpenJDK 8 to provide for the underlying Java Virtual Machine.  However, there is another Java Virtual Machine from Oracle that I could try running my Java programs on. With that information in mind, I decided to try running my Java programs with the Oracle Java Virtual Machine on my Raspberry Pi 3.<\/p>\n<h3>Installing Oracle Java 8 on my Ubuntu Server 15.10.3 image on my Raspberry Pi 3<\/h3>\n<p>To install Oracle Java 8 on my Ubuntu Server 15.10.3 image on my Raspberry Pi, I ran the following command:<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\nsudo add-apt-repository ppa:webupd8team\/java\r\nsudo apt-get update \r\nsudo apt-get -y install oracle-java8-installer\r\n<\/pre>\n<p>After the installation had completed, I verified my Java Virtual Machine version by running the following command:<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\njava -version\r\n<\/pre>\n<p>which returned me the following output:<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\njava version &quot;1.8.0_101&quot;\r\nJava(TM) SE Runtime Environment (build 1.8.0_101-b13)\r\nJava HotSpot(TM) Client VM (build 25.101-b13, mixed mode)\r\n<\/pre>\n<p>This meant that the Oracle Java Virtual Machine would be used for running Java programs on my Raspberry Pi 3. <\/p>\n<p>I then ran one of my Java hobby programs and was able to notice the significant improvement in performance.<\/p>\n<h2>Switching default Java runtime on Ubuntu Server 15.10.3 on my Raspberry Pi 3<\/h2>\n<p>For me, the Oracle Java 8 installer set its own runtime as the default Java runtime on my Raspberry Pi 3. In case when it doesn't, you can run the following command to set the default java runtime to Oracle Java runtime:<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\nsudo update-alternatives --config java\r\n<\/pre>\n<p>When I ran this command, I got the following output:<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\nThere are 2 choices for the alternative java (providing \/usr\/bin\/java).\r\n\r\n  Selection    Path                                            Priority   Status\r\n------------------------------------------------------------\r\n  0            \/usr\/lib\/jvm\/java-8-oracle\/jre\/bin\/java          1064      auto mode\r\n  1            \/usr\/lib\/jvm\/java-8-openjdk-armhf\/jre\/bin\/java   1063      manual mode\r\n* 2            \/usr\/lib\/jvm\/java-8-oracle\/jre\/bin\/java          1064      manual mode\r\n\r\nPress &lt;enter&gt; to keep the current choice&#x5B;*], or type selection number: \r\n<\/pre>\n<p>To further verify that the Oracle Java 8 runtime runs Java programs faster than the OpenJDK 8 runtime, I selected option 1 and ran my Java programs again. When I did that, I could observed the decrease in the performance of my Java programs. <\/p>\n<p>With that verification, I ran the <code>update-alternatives<\/code> command again to switch the default Java runtime back to the Oracle Java 8 runtime. <\/p>\n\n      <ul id=\"social-sharing-buttons-list\">\n        <li class=\"facebook\">\n          <a href=\"https:\/\/www.facebook.com\/sharer\/sharer.php?u=https%3A%2F%2Fwp.me%2Fp245TQ-8x\" target=\"_blank\" role=\"button\" rel=\"nofollow\">\n            <img decoding=\"async\" src=\"\/ph\/img\/3rd-party\/social-icons\/Facebook.png\" alt=\"Facebook icon\"> Share\n          <\/a>\n        <\/li>\n        <li class=\"twitter\">\n          <a href=\"https:\/\/twitter.com\/intent\/tweet?text=&url=https%3A%2F%2Fwp.me%2Fp245TQ-8x&via=Techcoil_com\" target=\"_blank\" role=\"button\" rel=\"nofollow\">\n          <img decoding=\"async\" src=\"\/ph\/img\/3rd-party\/social-icons\/Twitter.png\" alt=\"Twitter icon\"> Tweet\n          <\/a>\n        <\/li>\n        <li class=\"linkedin\">\n          <a href=\"https:\/\/www.linkedin.com\/shareArticle?mini=1&title=&url=https%3A%2F%2Fwp.me%2Fp245TQ-8x&source=https:\/\/www.techcoil.com\" target=\"_blank\" role=\"button\" rel=\"nofollow\">\n          <img decoding=\"async\" src=\"\/ph\/img\/3rd-party\/social-icons\/linkedin.png\" alt=\"Linkedin icon\"> Share\n          <\/a>\n        <\/li>\n        <li class=\"pinterest\">\n          <a href=\"https:\/\/pinterest.com\/pin\/create\/button\/?url=https%3A%2F%2Fwww.techcoil.com%2Fblog%2Fwp-json%2Fwp%2Fv2%2Fposts%2F529&description=\" class=\"pin-it-button\" target=\"_blank\" role=\"button\" rel=\"nofollow\" count-layout=\"horizontal\">\n          <img decoding=\"async\" src=\"\/ph\/img\/3rd-party\/social-icons\/Pinterest.png\" alt=\"Pinterest icon\"> Save\n          <\/a>\n        <\/li>\n      <\/ul>\n    ","protected":false},"excerpt":{"rendered":"<p>When my first attempt to <a href=\"https:\/\/www.techcoil.com\/blog\/setting-up-gitbucket-on-raspberry-pi-3-with-an-ubuntu-server-15-10-3-image\/\" title=\"Setting up GitBucket on Raspberry Pi 3 with an Ubuntu Server 15.10.3 image\" target=\"_blank\">install GitBucket on my Raspberry Pi 3<\/a> highlighted to me that it was the JVM that caused GitBucket to have sluggish performance, I did not invest more time to improve the performance of the JVM that I had installed on my Raspberry Pi 3. Instead, I went on to <a href=\"https:\/\/www.techcoil.com\/blog\/setting-up-go-git-service-on-a-ubuntu-server-15-10-3-image-on-my-raspberry-pi-3\/\" title=\"Setting up Go Git Service on a Ubuntu Server 15.10.3 image on my Raspberry Pi 3\" target=\"_blank\">install Go Git Service on my Raspberry Pi 3<\/a> to act as the Git server to manage the source codes of my hobby projects.<\/p>\n<p>However, I just couldn&#8217;t get over my belief that Java programs would perform badly on my Raspberry Pi 3; after all Java was the first programming language that I learnt and I often use it to build software at work. Furthermore, with an Ubuntu Server 15.10.3 setup on my Raspberry Pi 3, I could use my Raspberry Pi 3 as an integration server for my Java hobby projects and be pretty sure that if my Java hobby projects run on my Raspberry Pi 3, they will most probably run on a Ubuntu Server 15.10.3 <a href=\"https:\/\/m.do.co\/c\/68b7d9b94341\" title=\"Link to DigitalOcean\" target=\"_blank\">DigitalOcean<\/a> droplet as well.<\/p>\n<p>After spending some time researching the topic, I did manage to make my Java programs run around 10 times faster on my Raspberry Pi 3. This post documents the steps that I went through to speed up my Java programs on my Raspberry Pi 3.<\/p>\n","protected":false},"author":1,"featured_media":1220,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"advanced_seo_description":"","jetpack_seo_html_title":"","jetpack_seo_noindex":false,"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":true,"_jetpack_newsletter_tier_id":0,"footnotes":""},"categories":[4],"tags":[6,314,240,308,423,195,260],"jetpack_featured_media_url":"https:\/\/www.techcoil.com\/blog\/wp-content\/uploads\/Java-logo.gif","jetpack_shortlink":"https:\/\/wp.me\/p245TQ-8x","jetpack-related-posts":[],"jetpack_likes_enabled":true,"jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/www.techcoil.com\/blog\/wp-json\/wp\/v2\/posts\/529"}],"collection":[{"href":"https:\/\/www.techcoil.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.techcoil.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.techcoil.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.techcoil.com\/blog\/wp-json\/wp\/v2\/comments?post=529"}],"version-history":[{"count":0,"href":"https:\/\/www.techcoil.com\/blog\/wp-json\/wp\/v2\/posts\/529\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.techcoil.com\/blog\/wp-json\/wp\/v2\/media\/1220"}],"wp:attachment":[{"href":"https:\/\/www.techcoil.com\/blog\/wp-json\/wp\/v2\/media?parent=529"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.techcoil.com\/blog\/wp-json\/wp\/v2\/categories?post=529"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.techcoil.com\/blog\/wp-json\/wp\/v2\/tags?post=529"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}