Total Pageviews

Thursday, September 06, 2012

Copy your Firefox passwords to another Firefox on a different machine

Just in case you are in process of setting up a new machine and installing Firefox you might want to save a little bit of time.
There is a stackoverflow question concerning where Firefox saves its passwords. This information becomes very valuable in case you don't want to enter (and maybe can't remember) each and every password of websites which require authentification.
In my case it works copying the files:
  • key3.db
  • signons.sqlite
from a Firefox 13 installation under Windows XP to a new Firefox 14 installation under Windows 7 (64 Bit).
I don't say it will work always but this situation is working well.
The above mentioned files are located in your Firefox profile folder.

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.