Total Pageviews

Friday, August 17, 2012

Go and check out the Eclipse Memory Analyzer in case of OutOfMemory exceptions

I have to mention this great tool once again: The Eclipse Memory Analyzer is an awesome tool to analyze heap dumps and to find problems very fast. Especially the "Leak Suspects" feature is very useful for determining memory leaks in your application.

Thursday, August 16, 2012

Confluence Wiki PDF Export and generating a title page

Sometimes you have the requirement to export docs written in Confluence as PDF so customers who don't get access to your wiki can read it.
Often your company has guidelines for publishing documents to the outside (or for customers).
Confluence doesn't generate a title page as default when you do a single page export or a space export as PDF.
This article (sorry, only in german) describes how to achieve this in a few steps.
It only works using the space export to PDF not the single page export.
The author has forgotten to include the CSS styles for the title page so I will publish mine as a starting point.


 .KonzeptTitel {   
 font-size: 36px !important;  
 text-align: center;  
 padding-top: 150px !important;  
 }  
 .KonzeptThema {   
 font-size: 24px !important;  
 text-align: center;  
 padding-top: 100px !important;  
 padding-bottom: 200px !important;  
 }  
 .KonzeptAutor {   
 font-size: 16px !important;  
 text-align: left;  
 }  
 .KonzeptDatum {   
 font-size: 16px !important;  
 text-align: left;  
 }  
 .KonzeptVersion {   
 font-size: 16px !important;  
 text-align: left;  
 }  
 .pdfTitelblattText {   
 font-size: 16px !important;  
 text-align: left;  
 }  
Hope this helps somebody.

Thursday, August 02, 2012

SMTP Appender with logback and reducing log messages in email

Logback has some pretty cool features which makes developer life so much easier. Among them is configuring the buffer size of the log messages. Especially in conjunction with error messages delivered by the email appender adjusting the buffer size is very useful.
This blog entry shows you how to configure email alerts with logback and how to reduce the quantity of log messages in the error mail.
The default buffer size for log messages is set to 256 which might scatter your email with too much infos. The example given in the blog reduces the lines to 5 so you will receive only the latest 4 log messages (if logged) previously issued by your application including the error log message.

Wednesday, July 18, 2012

Using Preferences in Android

I am currently working on an Android app which can be configured by the user through preferences. Everybody who is somehow familiar with configuration dialogs in desktop applications or mobile phone apps knows that those configuration dialogs uses UI controls like checkboxes, radio buttons, list views, etc ...
On my trail through the official Android tutorial I didn't find any docs saying there is an Android preferences API which frees the developer from writing much code to display, read and store those preferences. Maybe I am to blind to find those docs ...
However, I found a few online tutorials which helped me a lot:

And of course the Android Preference API is always a good friend :-)

Friday, July 13, 2012

Stevie Ray Vaughan in action with number one

I just love this guy ... unfortunately I never saw him live on stage.


How to flush DNS cache

Sometimes it's good to know how to flush the DNS cache on your Linux or Windows box. Here is how to do it:

Linux

Restart the nscd daemon. In case it is not installed install it first

 apt-get install nscd  

then type the command

 sudo /etc/init.d/nscd restart  

or

 sudo service nscd restart  

There are a few alternatives to flush the DNS cache under Linux. See this blog posting to get a more complete overview.

Windows

Open a command shell and type

 ipconfig /flushdns  



Thursday, July 12, 2012

Solving "Too many open files" under Linux

Every now and then I got this error and everytime I start googling around how to fix this. So now I have decided to write it down and publish it to avoid using Google or any other search engines.

On any Linux most if not everything "is a file".
This is also the case for network connections. Thus, the error message "Too many open files" is more likely the problem of "Too many open connections".

The message comes from the operating system to tell you that the application opened a large number of connections. The Linux kernel has several securities to prevent an application from slowing the system by opening too many file handles.

In Linux there are two limits:
  • A global limit specifying the total amount of open file descriptors by the whole system
  • A per-process limit specifying the total amount of open files that can be opened by an application

Specifying the global limit

Determine the global limit with the command

 cat /proc/sys/fs/file-nr  

The result is a set of 3 numbers:

 1408  0    380226  

  1. The amount of currently opened file handles
  2. The number of free allocated file handles
  3. The maximum number of allowed file handles for the whole system
The maximum number on Ubuntu systems is somewhere around 300000. This should suffice in most of the cases. However, if you want to increase the size edit the file /etc/sysctl.conf as root and add/edit this:

 fs.file-max = 380180  

After editing you have to reconnect or restart your system for changed to be taken into account.

Specifying the per-process limit

To get the maximum value of file handles an application can open run this command

 ulimit -n  

Be aware, that this limit depends on the user running the application. You might get different results depending on the user running ulimit -n

On Ubuntu systems the value is set to 1024 which is in certain situations too low.
To permanently increase the value edit file /etc/security/limits.conf as root and add the following lines

 *      hard  nofile   65536  
 *      soft  nofile   65536  
 root   hard  nofile   65536  
 root   soft  nofile   65536  

With these settings any application running under any user can open a maximum amount of 65536 files. That should be enough in most cases.

The meaning of the four columns are:
  1. The name of the user the setting applies to. A "*" means every user except for user "root"
  2. Either "hard" or "soft" are possible values. A hard limit is fixed and can not be modified by a non-root user. A soft limit may be modified to the value up to the hard limit
  3. The type of resource to be limited. "nofile" means number of open files.
  4. The number of the limit to be set. In the case above the limit is always set to 65536
You have to reboot your system to apply the changes.

There is also a temporary method to set the per-process limit.

 ulimit -n 65536  

This limit of 65536 open files only applies for the life of the session or shell and is lost if you reconnect or restart your system. The value cannot be higher than those specified in /etc/security/limits.conf except if you are acting as user root.

How to measure the number of open files used?


To get the number of open files used by your application type:

 ps -aux | grep $APPLICATION_NAME  

$APPLICATION_NAME is the name of the process you want to get the process id for. This can be "java" for a running Java virtual machine or "tomcat" for a running tomcat container or XXX for any other application.

Copy the process id and enter:

 lsof -p $PROCESS_ID | wc -l  

where $PROCESS_ID is the process id you received from the ps command. The command returns the number of open files used by the process you specified.

Tuesday, July 10, 2012

Good examples of asynchronous method calls in EJB 3.1

Doing parallel processing in EJB containers before EJB 3.1 was a pain in the ass. You have to fiddle around with JMS and Message Driven Beans.
EJB 3.1 introduces asynchronous method calls and simplified the management of concurrently running tasks a lot. I found two pretty good examples how to use asynchronous method calls:

http://satishgopal.wordpress.com/2011/04/24/ejb-3-1-asynchronous-methods/
http://docs.oracle.com/javaee/6/tutorial/doc/gkkqg.html

Sunday, July 08, 2012

Speed up the Android Device Emulator under Windows

Everyone who is frustrated about the poor performance of the Android Device Emulator under Windows should follow the acceleration instructions from the official Google Android documentation site - section "Using the Android Emulator".
In particular when you are developing under Windows you should use the Intel Hardware Accelerated Execution Manager (HAXM). Unfortunately HAXM is not available for all Intel CPUs. So check the docs if your CPU is supported. 
After I installed it on my Windows 7 (64 Bit) system the emulator starts within 10 seconds.

Thursday, June 28, 2012

Alternatives to Spring JMX exporter in JSE/JEE without using Spring framework


Question:
Is there anything similar to the Spring JMX exporter out there WITHOUT using the Spring framework? SimpleJMX (http://256.com/sources/simplejmx/) seems to be reasonable but seems also to be a very young framework pushed only by a single person.

I'm in need of exposing a whole bunch of attributes, methods and classes as JMX but don't want to fiddle with the JMX API and writing tons of JMX interfaces. And there is no way to introduce Spring in the project (just in case you ask). Any hints or ideas are greatly appreciated :-)

Answer:
Ok, I have quickly evaluated SimpleJMX and JMXUtils. Both work as expected and are very similar to the Spring JMX exporter. However, I find JMXUtils to be more usable in my case.

With JMXUtils it is very easy to register/unregister MBeans to an already started platform mbean server. In my case I was using GlassFish V3 as application server and I didn't want to start another MBean Server just for my own mbeans.

As far as I can see the API of SimpleJMX does not allow this and you are either forced to start another MBeanServer using the SimpleJMX API and register the created mbeans (very easy with the API) or you start fiddling around with trying to register the mbeans into the platform mbean server. The later is a little bit more complicated and therefore I decided to use JMXUtils.

The downside of JMXUtils is the manipulation of the bean name. SimpleJMX uses attributes in annotations (domainName, beanName) which is very useful but with JMXUtils you have to know the syntax for naming mbeans when using mbean domains. All in all not a big deal but for my taste SimpleJMX has the better solution for this.

The bottom line is, that both libraries are great and do their job. I decided to use JMXUtils.

This question was also posted in this stackoverflow topic.