Archive

Archive for the ‘Java’ Category

How to find a concurrency bug with java?

August 25th, 2009
Daniel Schröter

How to find a concurrency bug – this was the question I asked myself some time ago.
It is always very hard to find a concurrency bug. Mostly you have no idea when it happens or if it is really a concurrency issue or some nasty bit of code. If it is a concurrency issue the question is if the bug is in your code or in a supplied library? Will the problem happen only on multicore processors or on any machine? Besides the technical problem the customer is eager to get a solution and management… we’ll i guess you know the story.
I won’t be able to tell you everything there is to know about concurrency testing – but I’ll show you a way that worked for me in most cases.
read more

 

Java, Methodology, Testing , , , ,

Strange Java 1.6.0 update 14 debugging problem

June 26th, 2009
Adrian Elsener

A few days ago, we upgraded the jdk we use for development. After this some developers experienced a special problem with our eclipse while debugging. When they set a breakpoint, eclipse did not stop. After a try and error phase we found a working solution. The problem disappeared when we set the vm parameter -Xms (define initial size of heap) to a higher value for the jvm inside eclipse. In our case we set -Xms to -Xms256m. We still do not know why this solution works. But we thought we’ll let you know.

 

Java, Software , , , ,

Luke – The Lucene Index Toolbox

June 13th, 2009
stefan.jaeger

Lucene offers great full text search capabilities. It is based on an index, which is maintained by Lucene. With Luke, the Lucene Index Toolbox (http://www.getopt.org/luke/) you can analyze your index and let explain queries.

After startup, you have to select your index. For this example, I created a test index with one file. It’s content is “this is a lucene test”. I used the StandardAnalyzer, which uses the WhitespaceTokenizer and filters out all tokens less than 3 characters and stop words. This will result in an index of the terms “lucene” and “test”.

image 

read more

 

Java ,

Perform XPath Queries inside Ant

May 17th, 2009
stefan.jaeger

Ant offers some XML features like the xslt task, which transforms XML files into other files. But unfortunately, with Ant you can’t make simple XPath Queries on a specific XML file.

 

Luckily, there is a nice open source solution called XmlTask, which offers many possibilities to work with XML files.

 

  1. Download the latest version of XmlTask from http://xmltask.sf.net
  2. read more

 

Java , ,

GC Viewer

May 15th, 2009
stefan.jaeger

Wrong use of the memory options can cause serious performance problems. To optimize the right memory size of the JVM or to find some critical memory issues, the GC log of the JVM can be very useful. Simply start the Java application with the option -Xloggc:<file>. Every GC action gets logged into this file.

To analyse this log file, there is a nice tool called GCViewer, which can be downloaded from http://www.tagtraum.com/gcviewer-download.html. GCViewer is able to display the memory usage of the application based on time and old/young generation heap space.

clip_image002

read more

 

Java ,

Use Groovy inside Ant

May 13th, 2009
stefan.jaeger

There are some kind of tasks, which Ant won’t do. One of them is the loop. There is no simple way to implement a dynamic for or while loop in Ant. What do i mean with dynamic? Let me make an example. Ant reads out a number of iterations from a property file (we call it the number x) and should perform a loop x-times to call another Ant task. And this can only hardly be done with Ant.

Groovy But fortunately, there is Groovy. Groovy is a scripting language, which runs in a Java Virtual Machine. And because of that, it can be easily integrated with Ant.

read more

 

Java , ,

Mockito

April 6th, 2009
Adrian Elsener

A few weeks ago, I started using Mockito. Mockito is a mocking framework for Java.

What mockito is able to do:
- mocking interfaces and abstract classes
- mocking concrete classes
- spy real objects

(http://code.google.com/p/mockito)

I liked mockito so much that I decided to present it to you…
read more

 

Java, Testing , , ,

Code City

March 11th, 2009
stefan.jaeger

Yesterday, I visited an interesting presentation from Tudor Girba. He showed us several ways for visualize code. One of the most interesting visualization was Code City.

 

image

(ArgoUML from http://moose.unibe.ch/tools/codecity)

 

read more

 

Java , ,

Eclipse will not find all classes with [Ctrl-Shift-T]

January 28th, 2009
Adrian Elsener

Today I stumbled upon the problem eclipse did not find some classes with the code completition or [Ctrl-Shift-T]. If you write the class name in the code everything looks ok. I tried to clean my workspaces with rebuild etc. did not work.

But there is hope: After deleting all content in .metadata/.plugins/org.eclipse.jdt.core eclipse re-indexes the workspace again and everything is ok. I guess -clean as startup parameter would work likewise but I can’t verify.

 

Java, Software , , ,

Eclipse and Ant – They really get along very well!

January 27th, 2009
Daniel Schröter

Have you ever used your own custom ant task in the eclipse environment. Well – I have written some ant tasks and they are being used by all developers in our company. But there’s the annoying thing that I always have to add the libs containing my tasks to the classpath. Nothing easier than this you might be thinking. Add it to ants classpath in the eclipse preferences. This works on my machine but what about all other developers? What about updates to the libs?

I guess I found the perfect solution for this problem. Write an eclipse plug-in that adds all libraries to ants classpath using the extension point of the ant plug-in and put the plug-in on an eclipse site so all developers can get it automatically.

That’s easy to say but how? Lets get our hands dirty…

read more

 

Java , , , , ,