Archive

Posts Tagged ‘java’

Hunspell4Eclipse 0.8.2 (beta) out

No Gravatar

Changes:

  • threshold feature
  • update site back to normal
  • limited Java support – reports misspelled words (underline), but no proposals
  • latest JNA

Link to project page: http://code.google.com/p/hunspell4eclipse/

Eclipse Spell Checker

No Gravatar

Eclipse has a built in spell checker. It’s based on word list files. It is just fine for languages that does not use pre- and postfixes extensively. But for languages like Hungarian, it is a no go. – I’ve tried to generate a word list of Hungarian words, but when I noticed that the word list reached 35 GB (not a typo!) I’ve canceled the process. – Just imagine Eclipse loading 35+ GB of dictionary…

In my search for a spell checker for Eclipse I found eSpell, but eSpell is also a word list based engine, so that is a no go too. I left with no choice but to create one. So here it is:

Hunspell4Eclipse

Immature. In beta stage. Lot to do. But it works…

Plans

I’m planning to provide content sensitive checking for Java and XML. Actually my plan is to create extension points for that purpose, to provide possibility for others to contribute too.

Comments please

I hope you’ll enjoy the plug-in and that you found it worthy to comment.

SLF4J Eclipse templates

No Gravatar

I’m sure lot of Eclipse developers are happy with Log4E, but for those who does not have Log4E or do not like to “pollute” Eclipse with plugins, I wrote few templates for SLF4J logging.

Just open Preferences and navigate to Java>Editor>Templates

Eclipse Preferences

Eclipse Preferences

…and press Import… button. And import: slf4j-eclipe-templates (download this file first)

Hit OK. Read more…

Ubuntu guy in a world of Apples… Part IV: Java Developer

No Gravatar

After a lot of work and some traveling I’m back, and I’m about to write about how do I manage to use Mac for Java development. (Note: This is the last part of the Apple Project series.)

First of all, let me describe what I use and how do I/we use it.

Eclipse is our choice of IDE. We use Subversion as SCM, Maven as a build system/dependency management/reporting/documentation/etc.. Beside these we use, (just to mention few that could be in relation with OS):

  • AspectJ
  • Spring
  • Hibernate for JPA
  • TestNG

Primarily we are building web applications, backed with RDBMS – so I need a some local database for my Mac, and our choice of RDBMS is PostgreSQL, but we use Oracle and DB2 as well.

Read more…

Bye, bye P2! Hello UM again!

No Gravatar

Had enough. P2 gave me just too much headache.

Today I removed P2 from my two production Eclipse installation. What a relief…

Update Manager (UM) works fine, as it worked in 3.3. Installed AJDT, Q4E, SpringIDE, TestNG, AnyEdit, … without any issue.

At my last few tries, I managed to install AJDT successfully, but after it I locked myself out. At next install P2 were missing AspectJ feature, and were willing to do nothing.

I read somewhere that P2 will not let you install uninstallable or wrong software… well… no comment.

I still beleave P2 is “not an evil”, and it will turn out to be great. But now I think it came in to suddenly and with lot of missing features/bugs. – I know this is the best way to test it… :-) , and I usually happily volunteer in these kind of testings, but not arbitrarily.

Autoboxing and synchronization…

No Gravatar

We were writing a small, low level code to provide sequence number generator. It was backed by database sequences, and it worked fine, or at least we thought so…

All unit tests passed fine. – We wrote some multi-thread testNG tests. So we were quite sure, everything is fine, until we got a bug report… They said we have duplications. Well the first reaction was “no way”. But the error came out again and again. To isolate the problem, we wanted to be sure that our code is fine, so we wrote a stress test: 10 threads, 20 iterations of getting 1 million numbers and storing it into a unique field of database table.

And the stress test started. We event started it 3 times: 3 separate VMs * 20 iterations simultaneously consuming 10 threads. And it ran… ran… for about 5h… and crash… oups, unique constraint violation… :-(

Well there is no way to reproduce this kind of error in debug mode, at least not until you know where the error might be. So we started an “eye debug” session… and after, about half an hour we got it! The code was:

private volatile Long last = -1l;
public final V getNext() {
  if (!initialized) {
   init();
  }

  synchronized (last) {
    if( last % increment == 0 ) {
      dbSequenceGetNextValue();
    }
    last++;
    return (V)last;
  }
}

Well, it looks fine… or at least at first glance. But this code is nasty.

The problem is with autoboxing. Well not exactly with autoboxing, but how we used it.

If you look at the line #11, that would be actually:Long.valueOf(last.intValue()++)

And that is the problem! We have a new object here! And we were using that variable to synchronize our block! Ouch.

Now the correct version is:

private volatile Long last = -1l;
//synch object
private volatile Object getNextSynch = new Object();
public final V getNext() {
  if (!initialized) {
    init();
  }
  synchronized (getNextSynch) {
    if( last % increment == 0 ) {
      dbSequenceGetNextValue();
    }
    last++;
    return (V)last;
  }
}

Of course we could use AtomicLong too, but we do not need that complexity…

Moral of the story:

  1. Always think twice, when you are coding thread-safe, synchronized, parallel, etc…
  2. Instant sugar is evil!

p.s.: Stress tests still running… :-) Hope we’ll get a result by tomorrow.

Hibernate 3.2.x and Groovy – ASM madness

No Gravatar

I was playing a bit with Hibernate and Groovy. I was about to examine the possibility of using Groovy producing JPA Entities.

As I use Maven 2, the natural way is to create a project and define dependencies. As a good Maven user I was looking for the best artifact in the maven repository. I found Hibernate, and Groovy too. I took the latest from both. For groovy there was a choice between groovy-all and groovy. The groovy POM file was more descriptive, so I took that one.

Now that was a bad idea.

The problem is: Hibernate depends on ASM 1.5.3 while Groovy depends on ASM 2.2. ASM is not backward compatible, so ASM 2.2 won’t work for Hibernate. It will fail with class not found exception, (and vice versa for Groovy). After a day of hacking Maven POM file, and looking for some solution, I found this. Just look at the last paragraph, there is the solution. Just pick groovy-all. So I did that, and everything is fine again. Or at least to thought so…
I work on a framework, so I need to use ASM to enhance or to create some code at runtime. I usually do that by using ASM Eclipse plugin, because that is the fastest and easiest path. But that plugin relies on ASM 2.2, and now I’m back where I was… :-(

Ok, I could use a class loader hierarchy, but that would mean special configuration for Maven, or even worst, special configuration at deployment.

I think the Hibernate team should consider the solution Groovy team made.

Or I’m going to do that. :-)

Nice and easy.