Showing posts with label Java. Show all posts
Showing posts with label Java. Show all posts

Thursday, December 2, 2021

How to set Java version for lein

To select specific Java (JDK) to use for leiningen, set environment variable JAVA_CMD

For example,

JAVA_CMD=/path/to/bin/java lein repl

Credit: https://gist.github.com/camsaul/c982019fd915510677236cd4b720a583#gistcomment-3439527 

Friday, June 26, 2020

Some usages of jstat

-gcutil

$ jstat -gcutil


This command shows utilization percentage of memory spaces of a java process.

S0: Survivor space 0
S1: Survivor space 1
E: Eden space
O: Old-gen space

GC activities

YGC: Young GC count
YGCT: Time spent by Young GC 
FGC: Full GC count
FGCT: Time spent by Full GC


-gc

$ jstat -gc

Find the current vm heap size by sum value under S0C, S01, EC, OC


More at https://docs.oracle.com/javase/8/docs/technotes/tools/unix/jstat.html

Tuesday, August 25, 2015

On OS X, Java Control Panel and Terminal show different Java versions

That's because Java Control Panel shows version of JRE for normal Mac user, but command line on Terminal shows version of JDK. To update JDK version, need to download the full package from Oracle website.
Older JDK version won't be replace automatically to allow us to switch back if we want. So we have to manually remove it by following the instruction here http://docs.oracle.com/javase/8/docs/technotes/guides/install/mac_jdk.html#A1096903

Credit: http://stackoverflow.com/a/28254333

Saturday, September 8, 2012

Experimenting Java library with Clojure

I'm reading Joy of Clojure. The book is a bit outdated in terms of library version. It was written when Clojure was at 1.2 but now Clojure is at 1.4 and 1.5 is development.

In one section of the book, it explains that we can easily use function show in clojure.contrib.repl.utils to display document of Java library but that was for Clojure.

According to Where Did Clojure.Contrib Go, show moved to clojure.reflect/reflect. Let play with it a little bit.

Pretty handy.

Note: you also can open Javadoc in browser with this snippet
(javadoc java.lang.Math)

Monday, November 22, 2010

[Java] What will be printed to a console?

ArrayList<Integer> list = new ArrayList<Integer>();
list.add(1);
list.add(2);
list.add(3);
list.remove(1);
System.out.println(list);

Monday, November 1, 2010

[Java] Jars inside Jar

Jar that contains multiple jars inside is not support directly by Java. There are some workarounds on this.
  • Put jars in to jar as ordinary files then load them with your own customized classloader. There is a tool such as One-JAR™ but some people told that it causes performance problem (I have not try this).
  • Extract jars to .class and pack them together to a single jar. You can archive this easily with Ant's Zip Task
For me, I choose the second approach. There are more workarounds in reference links below.

Java: Easiest way to merge a release into one jar-file
Is it possible to package all the jar dependencies in one big jar ?

Thursday, January 7, 2010

Java thread stack size

Today, I have just known that there's an another interesting parameter to set to JVM. It is java thread stack size.

With too high thread stack size, it will effect to low number of thread JVM can create - see this experiment. Not enough memory for java thread (cause from too big stack size) will produce "java.lang.OutOfMemoryError: unable to create new native thread"

You can set java stack thread size by adding -XssnK to JVM argument where n stands for a wanted size.

Now, I am not sure what is the default java thread stack size. Someone tells it is 512Kb. Another one tells it is up to the platform. One thing is that it's vary between each java versions. However, there is a way to get it from your running JVM. I got this trick from Get thread stack size at runtime thanks to claudio. Note that this trick may work only with *nix family.

First, you have to know your target JVM's pid (process id). If your system has only one JVM running, it is easy to use 'ps' or top to find it. But if it has many, my often used approach is to use

jps -lv

and justify it from the informations provided. If the informations are equally the same, help yourself :P.

Now you have target JVM's pid.

Then run following command

jinfo -flag ThreadStackSize {PID}

The jvm's set thread stack size will show to you in Kb.

Friday, June 5, 2009

[FIXED] This project needs to migrate WTP metadata

After I checkout code from SVN repository, some of my Eclipse's projects alert this error

"This project needs to migrate WTP metadata"

and it's no provide clue for solve them.

I found this thread Eclipse error: This project needs to migrate WTP metadata

There's a way to solve this error almost bottom of the page.

Just right-click at alerting project and click "Validate"

Then the problem must be solved

Collectd PostgreSQL Plugin

I couldn't find this link when searching with google https://www.collectd.org/documentation/manpages/collectd.conf.html#plugin-postgresq...