Archive

Posts Tagged ‘java’

Using SCM from within your Mojo

No Gravatar

There is a guide on the topic from Maven. But that guide is missing an example on how to use it from within Mojo.

So let me show you a short example on a topic… Read more…

Share

Hunspell4Eclipse 0.8.6

No Gravatar

Thanks to new members on the H4E team a new release could be downloaded from update site or Eclipse Marketplace.

The project is hosted under Google Code: http://code.google.com/p/hunspell4eclipse/

Eclipse Marketplace: http://marketplace.eclipse.org/content/hunspell4eclipse-0

Ohloh: https://www.ohloh.net/p/hunspell4eclipse

It is known to work with almost any variation of Eclipse – OS – HW out there.

Have fun with it.

Share

Provide log4j configuration fast and dirty

No Gravatar
If you are developing with Java, I’m sure you ran into a console output that looks like this:
log4j:WARN No appenders could be found for logger (org.apache.openejb.resource.activemq.ActiveMQResourceAdapter).
log4j:WARN Please initialize the log4j system properly.
log4j:WARN No appenders could be found for logger (org.apache.openejb.resource.activemq.ActiveMQResourceAdapter).log4j:WARN Please initialize the log4j system properly.
The message is clean: provide a log4j configuration. But, hey, I just want to debug/test/… it… Or I just want to change the debug level, but I cannot modify the app, or cannot find the (right) configuration…
I just need a fast solution for this.
So here it is:
  1. Create a folder and place a log4j.properteies file in it.
  2. Edit your log4j.properteies for your needs.
  3. Add the given folder to your apps classpath (as a first entry)

That’s it.

Read more…

Share

Debuging OpenEJB’s TomEE with Eclipse WTP

No Gravatar

This is just a short description on how to use OpenEJB with Tomcat to debug it within Eclipse.

The point is to be able to debug EJB applications from within Eclipse with a lightweight Tomcat container using OpenEJB.

Read more…

Share

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/

Share

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.

Share

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…

Share

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…

Share

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.

Share

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.

Share