Tomcat Cannot assign requested address – made me crazy

Today I migrated a Tomcat Server to a new host. Everything was in place but it won’t start showing me the following error:

Tomcat Cannot assign requested address

I’m happy ‘Nir Levy‘ had nearly the same problem 4 years ago. Here he describes what went wrong with his /etc/hosts configuration.
My problem was that I did not update the host name in the configuration for my module
After that everything was fine ūüôā
I *heart* blogs !

first look at javafx

Today I had my first look at javafx. Real nice but you must get used to the syntax.
After 1/2 hour of reading and 1/2 hour of modifying a nice netbeans example (original version from Michal Skvor) i end up with this. Not perfect but it has shown me how the javafx basics work.

winner screen


And after I read this ‘Deploy A Rich Internet Application Developed With JavaFX Technology‘ (another 10 minutes) i was able to deploy it to the web.

Start it

If you like it let me know

You can cheat by pressing ‘r’=remove single block. ‘s’=remove more ūüėČ

Source Code can be foundhere

sort a hashmap, fast

Imagine you have an hash map where key is an String and value is a integer.
Now you want to sort based on the value of each entry in this hashmap in descanding order.

Here is how I do it:

List<Map.Entry<String, Integer>> list = new Vector<Map.Entry<String, Integer>>(myHashMap.entrySet());
java.util.Collections.sort(list, new Comparator<Map.Entry<String, Integer>>() {
      public int compare(Map.Entry<String, Integer> e, Map.Entry<String, Integer> e1) {
          return (e.getValue().equals(e1.getValue()) ? 0 : (e.getValue() > e1.getValue() ? 1 : -1));

Now the list contains the sorted entrys from hashmap ‘THashMap myHashMap<String,Integer>’.
Iterate over it or copy it back to ‘myHashMap’ if you need to.

Hope this helps …

java decompilers

Because I have no recent Backup of the big java project I was working I have to decompile the class Files that are in this jar.
I found 3 different java decompilers for mac os x.

  1. MacJAD (google for Download)
    – onyl able to open single class files
  2. JarInspector (
    + can open jar files
    + correct 
    – unable to decompile the anonymous inner classes I use
    Рseems to be confused by nested catch and try blocks 
  3. JD-GUI (  
    + can open jar files
    + 90% able to decompiling anonymous inner classes

A big problem all tools share is that if you have nested iterations, for/while loops they all rename the variable you iterate over to ‘i$’. So it’s possible if your code looks like this:

while(iterator.hashNext()) {
    for(int varA; ....){
        for(int varB; ....){.....}

the decompiled code will end up looking this:

while(i$.hashNext()) {
    for(int i$; ....){
        for(int i$; ....){.....}

which isn’t really funny …

My conclusion is that JarInspector seems to be the best but if you need the inner class support use JD-GUI for the parts of the code those are in.


For those who don’t know there is some nice gnu package you can use anywhere a normal HashMap is needed.


import gnu.trove.THashMap;

and use it. The only thing that differs is speed and memory usage.

Currently I’m making a differential analysis for over 1800 documents. This means comparing all documents agains each other.
approx. (1800*1799)/2=1619100 comparisons. The average file size is 0.8 MB

With HashMap<String,Integer> I’ll use about 13Gig of Ram and need about 3h20min
With THashMap<String,Integer> I’ll never need more than 8 Gig and need about 2h40min

The THashMap is part of trove4j library.

It is descibed on their webpage:

“The Trove library provides high speed regular and primitive collections for Java.”

For more Infos visit their webpage at:

java hashCode inconsistent ?

While trying to make some kind of header check to see if someone modified the header of my property files I observed something I don’t understand.
I found out that the standard java Method ‘.hashCode’ that every Object provides behave some kind of stange.

Here is my Code

1. StringBuilder sb = new StringBuilder();
   try {
       int i = 0;
2.     for (String s : file2Text.getFileText("./test.txt", "UTF-8")\
                      .split(System.getProperty("line.separator"))) {
3.       if (i++ < 10) {
4.          sb.append(s);
         } else {
} catch (FileNotAccessibleException ex) {
5. System.out.println(String.valueOf(sb.hashCode()));

So I create a StringBuilder (1) and append (4) the first 10 lines (3) from
file ‘./test.txt’ (2). After that if simply print out the hash Code of the
String Builder (5). Note that the file I read in will stay the same.
I run it and it prints out

fine, so far.

Now I transfer my program to a Linux (2.6.18-6-amd64 #1 SMP  2008 x86_64 GNU/Linux) box.
Copy the  file test.txt and rerun my program.

Hmm, well thats not what I expected cause

Maybe something related to the system architecture because locally I’m working with Darwin
(9.6.0 Darwin Kernel Version 9.6.0: root:xnu-1228.9.59~1/RELEASE_I386 i386).

So I already thought that it wouldn’t be possible to make this kind of property header check.
While playing around I then rerun the my code with the same text file on the amd machine.
And suddenly my hash code changes to:


Ok again

1408212765, and again, 1408212765 and again 7281581206 and again 1408212765.


Why does my hash code changes? I read from the same file on the same system changing nothing between the runs.
Shouldn’t a hash value stay the same ?


because of too less time at the moment I’m going to investigate some time whenever there is time to have a closer look at this