wtorek, 17 września 2013

How to disable annoying java updates.

I use java. Every day. I know precisely what version I should use for given task, therefore I do mind being notified about "There is an update availabe. Would you....? "
NO. I would not :)

To disable this annoying feature on windows 7 (probably on every windows) you have to:
* run console as administrator
* run file C:\Program Files (x86)\Java\jre6\bin\javacpl.exe
* disable updated :)

Or you could run the file directly as an administrator, but using console is more natural to me :)

And that's all.

poniedziałek, 2 września 2013

SQL Developer and the User-Related Information Location

Sql Developer generates a lot of data stored by default in home directory. Usually it is not a problem, but if you have a quota on your directory, well... Fortunatelly there is a way to change the location of user related data: http://docs.oracle.com/cd/E18464_01/doc.30/e17472/intro.htm#CIHFCGCD
The only thing that must be done is to define IDE_USER_DIR environment variable.
But!
Before doing that you should copy already existing data to new directory, or at least export your connections :)


wtorek, 16 kwietnia 2013

RPi - Running services at boot

I wanted to start a few services while my Rasperry Pi is booting. Since my days as linux "administrator" are gone, I needed to do some research how to achieve that.

Services to be started: H2 database server, serial port listening service, tomcat - in that order.

Naturally, all applications have been installed.
First step - prepare script files:

/etc/init.d/h2 file:
#!/bin/bash

### BEGIN INIT INFO
# Provides:          h2
# Required-Start:
# Required-Stop:
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: h2 database
# Description:       h2 database
### END INIT INFO


test -f /lib/lsb/init-functions || exit 1
. /lib/lsb/init-functions

H2_HOME=/opt/h2
DAEMON=h2server
ARGS=


#PID=$(get_pid $DAEMON)

case "$1" in
 start)
  log_begin_msg "Starting h2 database"
   $H2_HOME/bin/$DAEMON $ARGS & #>/dev/null
   log_end_msg 0
   ;;
 stop)
   log_begin_msg "Stopping $DAEMON"
   kill `ps aux | awk '/h2.*jar/{print $2}'` > /dev/null
   ;;
 restart)
   $0 stop
   sleep 1
   $0 start
   ;;
 *)
   echo "usage: $0 {start|stop|restart}"  
esac


/etc/init.d/rxreader file:
#!/bin/bash

### BEGIN INIT INFO
# Provides:          rxreader
# Required-Start: $tomcat
# Required-Stop: $tomcat
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: rxreader
# Description:       rxreader
### END INIT INFO


test -f /lib/lsb/init-functions || exit 1
. /lib/lsb/init-functions

RXRD_HOME=/opt/rxreader
DAEMON=read
ARGS=


case "$1" in
 start)
  log_begin_msg "Starting h2 database"
   #[ -z "$PID" ] && 
   $RXRD_HOME/bin/$DAEMON $ARGS & #>/dev/null
   log_end_msg 0
   ;;
 stop)
   log_begin_msg "Stopping $DAEMON"
   kill `ps aux | awk '/rxreader/{print $2}'` > /dev/null
   ;;
 restart)
   $0 stop
   sleep 1
   $0 start
   ;;
 *)
   echo "usage: $0 {start|stop|restart}"  
esac

/etc/init.d/tomcat file:
#!/bin/bash

### BEGIN INIT INFO
# Provides:          tomcat
# Required-Start: $h2
# Required-Stop: $h2
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: tomcat
# Description:       tomcat
### END INIT INFO


test -f /lib/lsb/init-functions || exit 1
. /lib/lsb/init-functions

TOMCAT_HOME=/opt/apache-tomcat-7
DAEMON=startup.sh
ARGS=


case "$1" in
 start)
  log_begin_msg "Starting apache tomcat"
   $TOMCAT_HOME/bin/$DAEMON $ARGS & #>/dev/null
   log_end_msg 0
   ;;
 stop)
   log_begin_msg "Stopping $DAEMON"
   $TOMCAT_HOME/bin/shutdown.sh
   ;;
 restart)
   $0 stop
   sleep 1
   $0 start
   ;;
 *)
   echo "usage: $0 {start|stop|restart}"  
esac

When file are in /etc/init.d directory we have to run update-rc command, which installs (or removes) System-V style init script links:
sudo update-rc.d h2 defaults
sudo update-rc.d tomcat defaults
sudo update-rc.d rxreader defaults

Now you can restart RPi or start services manually:
sudo service h2 start
sudo service rxreader start
sudo service tomcat start

wtorek, 22 stycznia 2013

Java and RPi - continued


After I had installed both jdk (open and oracle's), I started wondering what is the difference between them, when it comes to performance. Recently I found some time in the evening and wrote simple tests, which are not very accurate, but give the general notion about performance.

Let's take a look into tests:
ArrayListAppendTest
List<Long> list = new ArrayList<Long>();
for (long l = 0; l <1000000; l++) {
   list.add(l);
}

ArrayListInsertMiddleTest
List<Long> list = new ArrayList<Long>();
for (long l = 0; l < 1000; l++) {
   list.add(l);
}
for (long l = 0; l < 10000; l++) {
   list.add(500, l);
} 

ArrayListSortTest
List list = new ArrayList();
for (int i = 100000; i > 0; i--) {
   String str = String.format("String nr %5s", i);
   list.add(str);
}
Collections.sort(list);

LinkedListAppendTest, LinkedListInsertMiddleTest, LinkedListSortTest are exactly the same as for ArrayList, but with subtle change...

DoubleAddTest
double val = 0.0;
for (int i = 0; i< 1000000; i++) {
   val += (double) i;
}

SinusTest
for(int i = 0; i < 1000000; i++) {
   double val = Math.sin((double) i);
}

StringAppendTest
String [] strings = new String[1000];
for (int i = 0; i < strings.length; i++) {
   strings[i] = String.format("Str %d", i);
}
String concat = "";
for (int i = 0; i < strings.length; i++) {
   concat += strings[i];
}

All tests *ISTest use various input streams, *OSTest - output streams.

When it comes to reflection tests, I tried to instantiate class using classe's newInstance method, in case of CallMethod test I'm calling one argument method using reflection. Simple...

For comparison I executed test on my ancient computer (Amd64 3500+). After that I compiled and run tests on Raspberry Pi using proper JDK.

And the resulst are... interesting (execution time is in ms):

Test nameJDK Oracle 1.7 @ AMD64 3500Oracle JDK 1.8 ea @ RPiOpen JDK 1.7 @ RPiRatio
ArrayListAppendTest 348,6 2632 10965,1 4,2
ArrayListInsertMiddleTest 72,6 285,7 1024,7 3,6
ArrayListSortTest 19,6 292,9 2394,4 8,2
BufferedFileOS 12,2 45,4 856,4 18,9
DoubleAddTest 0,2 35,8 390,5 10,9
FileISTest 25,3 183,8 231,5 1,3
FileOSTest 96,8 524,9 1618,9 3,1
LinkedListAppendTest 636,1 3393,7 16634,3 4,9
LinkedListInsertMiddleTest 23,3 99,5 2159 21,7
LinkedListSortTest 44,8 270,9 2225,9 8,2
ReflectionCallMethodTest 116,3 803,2 3496,7 4,4
ReflectionNewInstanceTest 55,5 202,5 542,4 2,7
SinusTest 268,6 562,5 3722 6,6
StringAppendTest 49,3 254,4 489,1 1,9

As you can see Open JDK in those test is far behind oracle's (in column Ratio you can see, how much slower Open JDK was :/).
I think I stick to JDK 1.8 ea...

sobota, 19 stycznia 2013

Java and RPi

If you gave a java developer a Raspberry Pi board, what programming language would he choose? You can make additional assumption, that he would be interested in writing a web application for RPi.
He would choose:
  1. C++
  2. Python
  3. or maybe Java?

Please send your answer anywhere you wish, in the meantime we start installing Java on RPi.

Most searches in google, if you want to find phrase "java raspberry pi", ends with plenty of links to articles, how to install the only proper one version, namely oracle java. But I would like to install for starters an open version.

Actually, installation process is not very sophisticated:
sudo apt-get install openjdk-7-jdk

When it's done, you can verify it quickly:
myuser@raspberrypi ~ $ java -version
java version "1.7.0_07"
OpenJDK Runtime Environment (IcedTea7 2.3.2) (7u7-2.3.2a-1+rpi1)
OpenJDK Zero VM (build 22.0-b10, mixed mode)

When it comes to web application, web container could be quite handy when running application. So far I haven't used jetty, therefore:
sudo apt-get install jetty8

When installation is completed (ignore an error while starting jetty) you need to update you startup scripts. But first, the only valid text editor should be installeed:
sudo apt-get install vim

Before we update a configuration file, let's see where java has landed:
update-alternatives --list java

and we get:
/usr/lib/jvm/java-7-openjdk-armhf/jre/bin/java

so java home is: /usr/lib/jvm/java-7-openjdk-armhf

Knowing all that important stuff we can modify a script file:
sudo vim /etc/default/jetty8

first thing, we shall allow jetty to start along wiht the system:
# change to 0 to allow Jetty to start
NO_START=0

after that, setting JAVA_HOME is proper thing to do:
# Home of Java installation.
JAVA_HOME=/usr/lib/jvm/java-7-openjdk-armhf

If we completed our work now, jetty could be accessed only on... localhost. In order to access web server from anywhere, we need to set JETTY_HOST as well:
# Listen to connections from this network host
# Use 0.0.0.0 as host to accept all connections.
# Uncomment to restrict access to localhost
#JETTY_HOST=$(uname -n)
JETTY_HOST=0.0.0.0

Let's restart jetty:
sudo /etc/init.d/jetty8 restart

and what we get is default page for our jetty server:



However...
I would like to have the possibility to use oracle's jdk as well.
But...
It's not so easy for me... At least not on a wheezy version I have installed nor with jdk 1.7.0_10.
The problem is that I had wanted to have more efficient system, therefore I've installed wheezy with hardware ABI, and current oracle's jdk can use only slower soft-bloat ABI.

Fortunatelly, Oralce released "early access" jdk 1.8 with JavaFX included (you can get that package from http://jdk8.java.net/fxarmpreview/)

Whern you download it and unpack in /usr/lib/jvm directory, following command should be executed:
myuser@raspberrypi ~ $ sudo update-alternatives --install /usr/bin/java java /usr/lib/jvm/jdk1.8.0/bin/java 1
myuser@raspberrypi ~ $ sudo update-alternatives --install /usr/bin/javac javac /usr/lib/jvm/jdk1.8.0/bin/javac 1

One more thing to - setting which java alternative should be used:
myuser@raspberrypi ~ $ sudo update-alternatives --config java
There are 3 choices for the alternative java (providing /usr/bin/java).

  Selection    Path                                            Priority   Status
------------------------------------------------------------
* 0            /usr/lib/jvm/java-7-openjdk-armhf/jre/bin/java   1063      auto mode
  1            /usr/lib/jvm/java-7-openjdk-armhf/jre/bin/java   1063      manual mode
  2            /usr/lib/jvm/jdk1.8.0/bin/java                   1         manual mode

Press enter to keep the current choice[*], or type selection number: 2

myuser@raspberrypi ~ $ sudo update-alternatives --config javac
There are 3 choices for the alternative javac (providing /usr/bin/javac).

  Selection    Path                                         Priority   Status
------------------------------------------------------------
* 0            /usr/lib/jvm/java-7-openjdk-armhf/bin/javac   1063      auto mode
  1            /usr/lib/jvm/java-7-openjdk-armhf/bin/javac   1063      manual mode
  2            /usr/lib/jvm/jdk1.8.0/bin/javac               1         manual mode

Press enter to keep the current choice[*], or type selection number: 2

Version check is simple:
myuser@raspberrypi ~ $ java -version
java version "1.8.0-ea"
Java(TM) SE Runtime Environment (build 1.8.0-ea-b36e)
Java HotSpot(TM) Client VM (build 25.0-b04, mixed mode)

Last thing to is is changing jetty configuration. I did that, and for now everything seems to work fine.

sobota, 5 stycznia 2013

New Year's Resolution

New year has come and with many New Year's Resolutions I've made one affecting this blog, namely I would like to try writing my posts in English (naturally I would like to translate all previous entries as well).
Why? There are many reasons. First of all I have to improve it. Not only my blog naturally ;) I haven't used written English for a long time (come on, short e-mails at work do not count). Besides, I really like this language and don't treat it as a tool.
Moreover, maybe I write something valuable one day... I that case more people could use that information (whatever).

At least my primordial assumption that this blog serves mainly me, is still valid.

Enjoy!