Showing posts with label Exception. Show all posts
Showing posts with label Exception. Show all posts

Wednesday, May 28, 2014

Takipi -- Tool for monitoring Exceptions in a Java Application

I came across this very nice monitoring tool for java application while looking at my news feed.



Honestly, I was first interested in getting the t-shirt that's why I started installing Takipi on my laptop. =)

Anyway to share my experience, I had problem running it in my laptop because I was using Java 6 for 64-bit. My Java 7 is only 32-bit so I had to install 64-bit version of Java 7. The installer doesn't clearly say the problem. You will only find the problem by logging in to Takipi and the error is shown in Dashboard as "Incompatible JVM"



So after installing 64-bit JDK 7, I configured Takipi on my Eclipse IDE and run my first application. Takipi will keep asking you to throw an exception. So I created a small app that will throw an exception. 

Exception 1




Exception 2






However in Takipi Dashboard, it doesn't show any of the exception thrown by my application.
I contacted their support thru their website and got a response from their Project Manager. He was very accommodating and provides helpful information. He told me that the tool is actually made for Production use and the application should be running for more than 60 seconds before it can catch any exception I throw.

So I updated my code and added the following:




After running my application, Takipi Dashboard now shows the exception thrown by the application.



The following information will be shown when View button is clicked.


It also shows the code snippet that causes the exception. 




You will also get an e-mail notification whenever an Exception is encountered.





This is indeed very helpful tool in investigating a problem in a production environment and will greatly help the developer in looking for the affected code instead of spending a lot of time replicating the problem in local machine to be able to debug and find the same code snippet that causes the problem. Not to mention the clip arts used in every part of the presentation of data is very entertaining.

To start working on Takipi, go to their application website: https://app.takipi.com/

Instructions are simple and easy to follow:



Enjoy throwing exceptions! :)

---------------------------------------------------
By the way, I already redeemed my free t-shirt and provided the delivery information. I'll update this blog post once I get my free t-shirt. 

Wednesday, April 2, 2014

ConcurrentModificationException when you see nothing wrong in the code!

You may sometimes encounter exception such as ConcurrentModificationException and tried to look at the code with the given stacktrace and see nothing wrong. 

java.util.ConcurrentModificationException
 at java.util.HashMap$HashIterator.nextEntry(Unknown Source)
 at java.util.HashMap$KeyIterator.next(Unknown Source)
 at c2.server.SessionManager.expireSessions(SessionManager.java:130)
 at c2.server.SessionExpiry.runThread(SessionExpiry.java:49)
 at c2.prm.IThreadAdmin.run(IThreadAdmin.java:276)

When you look at the code in SessionMager.expireSessions(), this is how it looks like:

                Set activeSessions = new HashSet();
                for (Iterator iterator = activeSessions.iterator(); iterator.hasNext();)
               {
                 Session session = (Session) iterator.next();

                 if (isSessionExpired(session))
                 {
                 activeSessions.remove(session);
                 }
             }

The exception is thrown in the highlighted line. On first look, were you able to pinpoint what's wrong in this code?

I admit. I didn't see what's wrong at first. I did a lot of research on google and tried few suggestions but nothing worked. My project is built on Java 1.3 therefore it's not easy to apply a fix especially if the code is not compatible.

After asking someone to have a second look and while explaining the situation, I finally realized what was wrong. It is the following line:

               activeSessions.remove(session);

So what it is trying to remove was an object from the collection itself!

By now you should have guessed the solution to this?

If you still haven't realized, the following is the solution.

                Set activeSessions = new HashSet();
                 for (Iterator iterator = activeSessions.iterator(); iterator.hasNext();)
                  {
                 Session session = (Session) iterator.next();
                
                 if (isSessionExpired(session))
                 {
                 iterator.remove();
                 }
                 }

Highlight to see the answer :)
AOL Directory Sumbit Url
Submit Site to Yahoo