My First Attempt at power efficient programming

I think the origin of the world is this way:-Man has not evolved all the species that are there have come from outside of this planet.. you name it and it's there when the lightning strikes a new species is born and so was the Human race, The most adavnced race and then came the SIllicon warriors and then the androids.. These androids have to be tuned and tamed just requires a few stiches to stabilize.. what these androids are doing are eating up the power// the jigsaw model of JVM is a great way of reducing the footprint of the jvm and it's for sure a great way ahead. I think that these bots can be highly optimized by switching off in the night.. battery optimizers, but above all reduce the JVM foot-print and optimize the code written to jmods.. extremely important is to do lazy loading whereever possible.. no eager loading The only question mark from my perspective is the design of the garbage collector.. Include finalize() method in each child class so that it is self managed. Also I would propose a local in-memory database for the JVM, and in the finalize method call release the memory from The IMDG.. here's some bit of initial code, it's quite buggy right now but any suggestions are welcome. The intent is to effectively collect garbage.. with a GC1 algorithm JVM settings -Xmx4000m -XX:MaxMetaspaceSize=2g -XX:+UseG1GC package com.kush; import java.util.Arrays; import java.util.List; import java.util.Optional; import java.util.concurrent.CompletableFuture; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; import java.util.concurrent.Future; public class MyFuture { public static void main(String[] args) throws Throwable { long startmilis = System.currentTimeMillis(); MyObject myObj = new MyObject("Test", "Test2"); MyObject myObj1 = new MyObject("Test1", "Test12"); ExecutorService execSer = Executors.newFixedThreadPool(4); Future fut = execSer.submit(myObj); Future fut1 = execSer.submit(myObj1); transformInput(1000); System.out.println("not completed"); fut.get(); if (fut.isDone()) System.out.println("not yet completed"); transformInput(1000); fut1.get(); if (fut1.isDone()) System.out.println("completed"); execSer.shutdownNow(); long endmilis = System.currentTimeMillis(); System.out.println("test duration" + (endmilis - startmilis)); // myFuture.finalize(); } private static void transformInput(Integer max) { Integer sum = 0; for (int i = 0; i < max; i++) { sum = sum + i; } System.out.println("sum" + sum); } private int getNumber(int a) { return a * a; } } class MyObject implements Runnable { public String str = "test"; public String str1 = "test2"; public MyObject(String str, String str1) { this.str = str; this.str1 = str1; } private int getNumber(int a) { return a * a; } public void run() { MyFuture mf = new MyFuture(); String l = "9223372036854775807l"; int l1 = 200; try { MyObject[] listOfObjects = new MyObject[l1]; List list = Arrays.asList(5, 9, 14); list.stream().map(num -> CompletableFuture.supplyAsync(() -> getNumber(num))) .map(CompletableFuture -> CompletableFuture.thenApply(n -> n * n)).map(t -> t.join()) .forEach(s -> System.out.println(s)); for (int i = 0; i < l1; i++) { StringBuilder str = new StringBuilder(l); MyObject obj1 = new MyObject("uu1", "uuy"); listOfObjects[i] = obj1; str.append(i); for (int j = 0; j < l1; j++) { Optional obj21 = Optional.ofNullable(listOfObjects[j]); long lrandom = (long) (Math.random() * 1000000); for (long k = 0; k < lrandom; k++) { if (obj21.isEmpty()) continue; else { // obj21.get().finalize(); } } } for (int kk = 0; kk < l1; kk++) { listOfObjects[kk] = null; } // System.gc(); } } catch (Exception e) { e.printStackTrace(); } try { } catch (Throwable e1) { // TODO Auto-generated catch block e1.printStackTrace(); } } protected void finalize() throws Throwable { System.out.println("test qw2e"); } public Object call() throws Exception { run(); return new Object(); } }

Comments

Popular posts from this blog

Hibernate Many to Many Relationship

Why Integral Calculus limit tending to infinity a sacrilege

Introduction