https://piotrminkowski.com/2020/03/10/best-practices-for-microservices-on-kubernetes/
java
-
Best Practices For Microservices On Kubernetes
-
The Unsafe Class: Unsafe at Any Speed
https://blogs.oracle.com/javamagazine/the-unsafe-class-unsafe-at-any-speed
From time to time, you may need to break the rules. In the Java platform, this is normally accomplished by using one of three primary mechanisms: reflection, class loading (including associated bytecode transformation), and
Unsafe. -
Quickly Analysing A Heap Memory Leak by Jack Shirazi
-
Persistent Large Maps in Java with MapDB
-
A tool to convert CSV, YML, XML, JSON and JSON-LD – oi v0.1
First release of oi is ready for testing. oi is an experimental command line tool to convert structured data from one format into another. The first release comes with rudimentary support for CSV, JSON, XML, YML and JSON-LD. The basic idea is to provide a straight in-out/out-in command that might not work completely correct but complements with other tools (jq, xsltproc, sed, grep, awk, etc. ) to manipulate structured data on the command line.
Install
wget https://schnasse.org/deb/oi_0.0.1.deb sudo apt install ./oi_0.0.1.deb # installs openjdk-11-jreExample Usage
- Convert
passwdtoyml(use-tto print different formats)
oi /etc/passwd -d":" --header="login,password,uid,gid,comment,home,shell" -icsv- List some disk info in
yml(use-tto print different formats)
lsblk |grep -o sd.*|awk '{print $1 ";" $4 ";" $NF}'|oi -d";" --header="device,size,mount" -icsv- Create adhoc Json-Ld Context for some arbitrary Json-API
curl https://api.github.com/users/jschnasse|oi -ijson -tcontext - Convert
-
Java: Simple Read/Write of Maps as Json
You can use tools like Jackson to serialize and deserialize maps to json an vice versa.
Example
@Test public void loadMapFromFileAndSaveIt(){ Map<Object, Object> map = loadMap("map.json"); map.put("8", "8th"); map.remove("7"); saveMap(map,"/path/to/map2.txt"); } private Map<Object, Object> loadMap(String string) { ObjectMapper mapper = new ObjectMapper(); //should be initialized outside! try (InputStream in = Thread.currentThread().getContextClassLoader().getResourceAsStream("map.json")) { return mapper.readValue(in, HashMap.class); }catch (Exception e) { throw new RuntimeException(e); } } private void saveMap(Map<Object, Object> map,String path) { try (PrintWriter out = new PrintWriter(path)) { out.println(toString(map)); } catch (Exception e) { throw new RuntimeException(e); } } public String toString(Object obj) { try (StringWriter w = new StringWriter();) { new ObjectMapper().configure(SerializationFeature.INDENT_OUTPUT, true).writeValue(w, obj); return w.toString(); } catch (Exception e) { throw new RuntimeException(e); } }If the file
map.jsonon your classpath contains{ "1":"1th", "2":"2th", "3":"3th", "4":"4th", "5":"5th", "6":"6th", "7":"7th" }The code above will modify it and writes it to a file
/path/to/map2.txtthat will contain the modified map.{ "1" : "1th", "2" : "2th", "3" : "3th", "4" : "4th", "5" : "5th", "6" : "6th", "8" : "8th" } -
Java Features
-
HTTP API in Java 11
-
Machine Learning for Java Developers
-
JPackage – Launch Java Apps without JVM
The jpackage tool of Java 14 can be used to create platform specific packages of java apps. The app does not require a JVM to run.
Example
/opt/jdk-14/bin/jpackage --name etctoy --input target --main-jar etctoy.jar
The call is made from within a maven project. etctoy.jar is a fat-jar (size 6.6M) but the call should also work for regular jars with further dependencies in the target directory (see –input parameter).
The result is a debian package that installs the app under /opt/etctoy
sudo dpkg -i etctoy_1.0-1_amd64.deb
The installation uses 140M of disk space.
To make the tool available via command line on should link the binary into /usr/bin
sudo ln -s /opt/etctoy/bin/etctoy /usr/bin